I would fly from Lima to Cusco. We went with LC Peru. Cheap flights and beats 22 hours in a bus!
Lots of villages/towns in the Cusco/Sacred Valley area. And lots of hiking. You can do day hikes from Ollantaytambo. For example:
https://moon.com/2014/02/three-great-day-hikes-in-ollantaytambo-peru/
For Machu Picchu we chose not to go by train. This is what we did:
We took a shuttle from Ollantaytambo to Santa Teresa. In the morning a shared van to Lucmabamba. A trail starts there that takes you to the Llactapata ruins and then down to the river and to Hidroelectrica. The hike is beautiful (cloud forest, birds, butterflies, flowers). At Llactapata it was cloudy at first but then the sun broke through the clouds and the view is incredible. We got our first view of Machu Picchu from there!
From Hidroelectrica we walked along the train tracks to Aguas Calientes. It is a nice walk (more butterflies and birds as well). It was a long but amazing day.
At MP we hiked up MP Montana.
We also took a bus from Cusco that was heading to Pisac but got off at Tambomachay and walked down past other ruins to Sacsayhuaman (which should not be missed) and back to Cusco.
We also enjoyed hiking up to the Pisac ruins (from the village) and back down. And we hiked from Maras to Moray and back to Maras and then from Maras to the salineras and on to the river and the road leading to Urubamba. Outstanding scenery and of course Moray and the salineras are amazing.
We didn't do the Huchuy Qosqo hike yet... next time.
If you like to hike also consider the Colca Canyon (take a bus from Arequipa to Cabanaconde). We went trekking in the canyon on our own and spent two nights down in the canyon.
We felt safe everywhere (just use common sense of course). We traveled mainly by public bus/minibus/shared taxi.
You can check availability (and buy tickets) for MP here:
http://www.machupicchu.gob.pe/
If you do want to go by train to MP you can buy tickets online (Peru Rail or Inca Rail).
I have not been to Bolivia (yet!).