Temperatures are fairly stable year-round—it's colder in the highlands and hot in the lowlands. The rainy season is October-April, and most travelers go during the dry months that coincide with North American and European summer vacations. Many Peruvians travel during this time as well, especially for the national holidays in late July, when prices can double.
The dry months are by far the best for camping and climbing trips in the Andes. The heaviest rains in the highlands are January-April, and disruptions in bus traffic because of landslides can be severe, especially in February and March.
Be sure to take a sweater (or something heavier) when you go to Cusco and Machu Picchu. A rain poncho is also useful both in the city and out on the trails. The best times to visit are May and September, missing the busiest tourist months and skirting the rainy season, but you can go year-round and have a wonderful time.