I'm with Wasleys on critiquing your itinerary. Fort William is too far from Stirling to be done on a day trip. and there is too much scenery in the Fort William area that you'd be missing.
I'd suggest staying in Edinburgh for your first three nights - if you haven't already done so, find accommodation with free or reduced price parking. On your first day, see as much of the city as you can before the jet lag kicks in.
On day two, spend it exploring.
On day three, take your day trip to St Andrews.
On day four, take the A702 straight south (well, actually south-southwest) out of Edinburgh. Once the A702 meets the A76, you'll be almost at Closeburn Castle. That is a very pretty drive. Visit the castle and surrounding area, then take the M74 to the M73 to the M80 for Stirling. Spend the night in Stirling. Not so pretty a drive, but it will save you time.
On day five, take the A84 west from Stirling to Lochearnhead, the A85 west to Crainlarich, then the A82 through Glencoe, and on to Fort William. Use Fort William as your base for exploring on days five and six. Stay overnight both days.
Day seven: Make your way back down to Edinburgh. Leave enough time to visit sites that you'd like to visit on the way, or if there are additional sites in Edinburgh that you'd still like to see, then take the shortest route possible back to the city. (A82 to the Erskine Bridge, then the M8 to Edinburgh looks like the easiest route.)
Day eight: Drop off the car, and jet off to Ireland.
Hope that helps!