For maximum xp do all the side stuff at the lowest possible level that doesn't show up as grey, then when there are no side quests below the main ones in terms of levels then do those. Rinse and repeat.
I hope that wasn't too confusing.
Oh okay. That was sort of my strategy with fallout 4 until I realized the game is pretty good about level scaling the story missions and I blazed through the story. Then I realized if I don't delay the story with side quests the storyline is actually pretty short. Just feels lame to do all those side quests now that I destroyed the Institute. It feels like I'm just running errands for a land that has no true big baddies threatening it. And far harbor is almost entirely unplayable for me. 25 dollars in the toilet.