The swelling and pain that you describe may be due to a hernia or hydrocele. Most children do not have discomfort with these. They are related to the way a certain structure in the groin region develops. This is distinctly different than the hernias that adults may develop from heavy lifting with a resulting tear of the muscles of the abdominal wall. He will tend to have discomfort after being up and around and especially after athletic activities with the resulting increase in abdominal pressure that forces a piece of intestine or omentum (an internal fatty structure) into the hernia sac. A hernia does need to be surgically corrected as a piece of intestinal can get caught in the sac and have its blood supply cut-off.
A hydrocele in a child is quite similar to a hernia except that fluid from the abdomen fills the sac by the same mechanism. There is not the risk of something getting caught but the swelling does not get better and may well get larger over time.
There is an unlikely possibility, given your description, that he has been having intermittent twisting (torsion) of his spermatic cord. This can result in the death of the testicle if it stays in the twisted state for more than 6-8 hours. He needs to be seen acutely by a pediatric urologist or general/pediatric surgeon when he is having symptoms.
The penile pain that you describe is not