Have you looked into having an special education evaluation done? Your son sounds like what my son would be if he hadn't gotten special education qualified. Writing was and remains physically painful for my son, and he frustrates easily, despite being very bright in many areas. The basic school day in so many ways does not suit him, and yet he loves to learn.
At our request, my son was evaluated for special education at the start of second grade. At the time I referred to it as this gap, between how it seemed he should be able to perform in school, and the reality of how he was performing in school. Like there was some giant rock in the way that he could feel but couldn't describe. He saw it, and it frustrated him; we saw it, and were confused for him. I wanted to find out how to help him cross that bridge. Honestly, at first the IEP team was skeptical, but they went full force into the evaluation process, and ended up thanking us for requesting it, because they determined that he most certainly needed services and accomodations to succeed in school. He has a school use diagnosis now of mild Aspergers and, honestly, it was like being handed a set of keys.
If your child is failing at school despite appearing to be bright, something is wrong either acedemically (an undiagosed condition or so bright he's bored) or socially (is he being teased?). His response to not knowing how to handle that conflict is to tune out, turn in, self-protect.
Definitely consider Asperger's if you have not already. Contrary to what many believe, these are emotional kids, who simply have brains that work very differently. It's very missunderstood.
While I hate putting kids into labels, ours has been a key. It's what you do with it once you have a label that matters.