What is the best way to reach Zagreb from Bucharest in terms of cost and time?
Definitely fly.
Train takes 25 hours with a connection at Budapest. How to Look Up Train Schedules and Routes Online gives you the DB train schedule link and tips for using it. The Budapest-Bucharest night train is probably not the place you'd want to try a night train, if you don't have previous experience of them.