All the high-season/low-season trade-offs are here. Winter (June through August) means drier weather and easier traveling, but it's prime vacation time for those in the northern hemisphere. Don't forget that three major observances—Inti Raymi (June 24), Peru's Independence Day (July 28), and Santa Rosa de Lima (August 30)—fall during this time, and translate into exceptionally heavy crowds of Peruvian travelers. The result is higher winter lodging prices and larger crowds. Prices and visitor numbers drop dramatically during the summer rainy season (October through April). For near-ideal weather and manageable crowds, consider a spring or fall trip.
In January and February the weather could most likely wreak havoc with your travel plans. But it's also the time when you can enjoy Machu Picchu without the crowds. Mudslides are an occasional problem when visiting during the October-April rainy season. It's rare, but visitors have been stranded at Machu Picchi or between Aguas Calientes and Cusco if the slides block the way, but usually only very briefly.