There are so many things that could be causing this, most of them not serious at all, and I am sure you will get lots of ideas from the smart moms on this site.
I keep going back to the headaches, though. I just have a feeling he has some dry sinus issues. It's pretty common, in adults as well as kids. Especially if you are doing a lot of swimming, and if you have a good air conditioning system at home.
Ask you pediatrician to check for any problems,
then get a saline nasal spray meant for children. We use one called "Little Noses". You can use it several times per day to keep him from getting all dryed out in his nose and sinuses. Also, put a cool mist humidifier in his room. Run it day and night, but especially at night while he is sleeping.
If he will tolerate it, you can even put a little of one of those menthol rubs (we use Vicks) on the end of his nose. Not much, though. It can be pretty strong for a little guy.
Be sure he is staying properly hydrated during the day. Some kids hate to drink water. If you have one of those, give him Kool-Aid, popsicles, whatever you can get down him. Less sugar would be better, but some kids just won't drink water, and it is more important to get the fluids into them than it is to worry about a little sugar in Kool-Aid.
One other thought ..... does he have tonsil problems ? Are they large and cause him to snore when he sleeps ? If this is happening, he could be having periods of not getting enough air when he sleeps. (Similar to what happens to a person with sleep apnea) When this happens, it causes the child to wake up (to gasp for air) then some children aren't very good at going back to sleep. They just figure that if they are awake it is time to get up and play.
This lack of oxygen will also cause headaches.
Just a couple of things to check for. They are easy to check for, and pretty simple to cure.
Good luck ! Let us all know how things turn out, please.
:o)