There isn't anything special about your itinerary - travelling through Canada is the same as flying over water to other non-mainland US areas. For the US part of the question, see the related questions on the right (e.g. Can we get a new visa waiver in Canada, for Alaska, when our old one expires in the US?).
To summarise, your VWP visa clock starts ticking from the moment you first set foot in US territory, Alaska in your case. It does not stop until you go somewhere other than US, Canada, Mexico or the Carribean. Therefore you will need to make sure that the time from when you first enter Alaska, until when you leave the USA to enter Mexico, is within 90 days if you want to use the Visa Waiver Program. (Also ensure your return flight does not depart from, or transit through, the US.)
I'd consider applying for a US tourist visa if you wish to keep your itinerary.
If you are from a visa waiver program country and you are coming for tourism or business (but not for employment or as a working member of the media) you may enter into the U.S. (including Hawaii, Alaska, Puerto Rico and the U.S. Virgin Islands) for up to 90 days. If you wish to visit the U.S. for a longer period of time, you will need to obtain a visa.
If visiting the U.S. under the visa waiver program you may not apply for an extension of stay.
If you go to Canada and Mexico or the Caribbean, and while you are there, your initial 90-day period of entry expires, but you need to come back in to the U.S. to fly home, you may encounter a problem. The terms of the VWP are very clear - it is only to be used for occasional, short visits to the U.S. If the CBP Officer thinks you are trying to "reset" the clock by making a short trip out of the U.S. and re-entering for another 90-day period, you can be denied entry. (If that happens, you will have to obtain a visa for any future travel to the U.S.) In order to be re-admitted to the U.S. shortly after a previous admission expired, you will have to convince a CBP Officer that you are not trying to "game" the system.
For Canada, the length of your entry visa under the visa free program is determined by the officer at the border when you initially enter. It is usually granted for a maximum of 6 months; for any longer you will need to apply for an extension 30 days prior to expiration or get a visa before you leave.
I believe the restrictions are the same - going to the US and returning does not reset the Canadian visa clock either (I definitely did not get any additional stamps or marks when I hopped between the two countries). I'm struggling to find any official evidence of this though; the Canadian Immigration and Citizenship website (http://www.cic.gc.ca/english/visit/visas.asp) is very vague on this topic.
Nevertheless, the Canadian restrictions are moot if you want to use the US VWP with your current itinerary because that period is shorter.