I lived in Ancorage for two summers. I think the best time to visit is at the beginning of June. The snow is almost totally off the lower mountains at that time and the bugs aren't horrendous yet. Maxium daylight occurs on June 21st with 19 hours 21 minutes of light. Don't sweat that though. Another good thing about June is the king runs will be starting. If you want to fish for the biggest salmon on earth, here's your chance! One thing to avoid in AK is the rain that will come during July (1.85 inches)/Aug (2.59). Sept has even more rain.
May I make a suggestion for your Denali hike....don't neglect Denali State Park. It is right next door to the National Park, only not near as strict on rules and regs as its big brother. It's just as beautiful though! Not as much wildlife, however. In the National Park, they only allow an extremely limited number of back country hikers in at a time. You HAVE to camp at specific sites and you have to tell them which site you will be at, at a certain time. WAY too constrictive for me! But the State Park has no rules like this because they aren't overun by visitors. I've done a 30 mile, moderate difficulty, 4-5 day hike twice in Denali State Park. It was SO awesome and both times I had amazing views of Denali (the mountain) right across the valley. In August you will find the wild blueberries in season. They are litterally covering the ground everwhere and you can just stop and eat whenever you feel like it!
Sorry for the long post, but I LOVE AK!!