Start with your dates. Outside Ramadan and the school holidays, hotels close to the Haram are easier to find and noticeably cheaper, and the mosques are calmer.
Decide next how you will divide your nights. Most first-time visitors spend more of the trip in Makkah and two or three nights in Madinah. Booking the Makkah stay first makes the rest of the plan fall into place.
Finally, arrange your transfers before you fly. A driver waiting at Jeddah airport saves an hour of negotiation after a long flight, and the road to Makkah takes a little over an hour.