My 7 yr old dd has experienced the same thing. Once she's feeling settled the stomach aches go away, but if she is in a new situation, it takes her a long time to feel comfortable and she has stomach aches.
She's had a lot of changes in the past 1.5 yrs and lots of stomach aches. Now that the end of the school year is approaching, she hasn't had any stomach aches for awhile, but it took much of the school year.
I'm quite sure it is stress-related for my dd. In fact, one day they did a thing in school where they had to draw a picture of how they feel when mad. She drew a picture of herself with big colored spirals and circles right on her stomach -everything in the picture was focused right there. That was very telling, I thought.
I hope your little one gets over his anxieties. I know how hard it is. Since he is doing well in school, could it be social stuff going on that is stressing him out. Will he talk about it? When my dd would complain about the stomach aches, I told her that sometimes when we aren't feeling good about something it can make our tummy's hurt, but if we talk about it sometimes the tummy ache will go away. Don't know that it really worked, but she's pretty closed with her emotions, so I just wanted to let her know that if she wanted to talk about anything I would listen and maybe it would help her tummy.