The itinerary seems relatively easy in terms of finding cheap travel options, so we see it as follows:
Budapest-Vienna: here you have two major budget options: a) purchase in advance discounted 13 EUR ticket (called SparSchiene), Hungarian railways sells it online (
http://elvira.mav-start.hu/elvira.dll/xslms/), but since it is in limited number per train, then better to buy it as early as possible; b) in case you don't want to purchase anything in advance, then it makes sense to go with the so-called tourist ticket (Kirándulójegy), it cost 25 EUR per person (or 31 EUR in case you want a city transport pass for Vienna for two days). This kirándulójegy actually a return ticket sold in unlimited number, but you will just use it one way.
Vienna-Prague: here also a few option. Easiest one will be to purchase discounted ticket for the direct train -
https://ticket.oebb.at/bin/frame_ticket.pl?ticket=jticket.pl&LANG=EN , start from 29 EUR per person. But since there is two passengers, then it also makes sense to use Einfach-Raus-Ticket, basically daily pass for up to 5 passengers for all the Austrian regional trains. Use it till the Austria-Czech border (like Gmund- C.Velenice) while from there you can get (either online -
https://www.cd.cz/eshop/search.aspx , on board of the train from the conductor or at the station) domestic Czech ticket to Prague, with the mini-group discount it will cost you from 338 CZK (app. 14 EUR) for both. This option is also interesting since allows you to make stopovers and visit interesting places on the way from Vienna to Prague.
Prague-Germany: here you have many options, everything depends on what you would like to see. You can either buy discounted tickets from Czech Railways eShop (link was given above) for the direct trains till Dresden, Leipzig, Munich etc. Also you can travel with SONE+DB/CD-Net+DB (more on those on our Czech Republic page), while then in Germany with a help of Lander tickets. Or just with regular mini-group discount till the last Czech station and again Lander tickets from there etc.