If you are already flying to Frankfurt you can get your airline to add train travel (Rail-Fly option) to your ticket. This will work out cheaper than buying the train ticket when you're there. Otherwise, the train ticket Stuttgart will cost 40€ round-trip for a Baden-Wuerttemberg day train ticket which covers all the regional trains and all local transportation (buses, U-bahn, S-bahn within Stuttgart.
Rail&Fly tickets There are two types of Rail&Fly tickets. If you are flying Business Class, book a first class Rail&Fly ticket and if you're flying Economy Class, book a second class Rail&Fly one. You do need to book your Rail&Fly ticket while you are booking your flight to avoid a re-booking fee later on for adding the reservation to your booking later.
Rail/fly tickets are only valid Rail/fly tickets are only valid for international flights either departing from or arriving in Germany. You cannot get them for domestic German flights, connecting flights or flights to and from Amsterdam, Brussels, Paris, Salzburg, Vienna or Zurich.