Leuchars is the closest station. It is five miles away. there are normally taxis waiting and there is also a regular bus service to St. Andrews which runs in conjunction with the arrival of the trains.
Here are some links that you may find useful:
From Edinburgh
Head for the Forth Road Bridge , then join the M90 and stay on this road until junction 2A signposted Glenrothes, Kirkcaldy, this will take you on to the A92 where you can then follow the signs for St. Andrews. To view the route on-line go to www.theaa.com and put in Edinburgh to St. Andrews.
From Glasgow
Leave Glasgow on the M8 and head for the Kincardine Bridge, once over the Kincardine Bridge take the A985 and head for Glenrothes, Kirkcaldy, this will take you on to the A92 where you can then follow the signs for St. Andrews. To view the route on-line go to www.theaa.com and put in Glasgow to St. Andrews
From The North
Head to Dundee and cross the Tay Road Bridge, once over the bridge follow the signs for St. Andrews. To view the route on-line go to www.theaa.com and put in Dundee to St. Andrews
The postcode for your satnav is KY16 9DQ