The best way to travel from Barcelona to Madrid is via high speed train AVE. Buses might be cheaper but they are slower and not comfortable. If you book in advance, you could even find a cheap flight but you will spend too long to get to the airport on both ends. So I recommend taking the train.
There are no overnight train from Barcelona to Madrid. There is, however, an overnight bus, but buses in Spain are uncomfortable and make a zillion stops.
Attractions en route
There is nothing of great interest in the middle between Barcelona and Madrid. If you go by bus, you could stop in Zaragoza I guess. I’ve been there quite a few times while studying a postgraduate course and I found it pretty but not really interesting. If on a tight schedule, I wouldn’t use Barcelona time to visit Zaragoza.
A good site to look for options to get from one place to the other (gives you all plane, train and bus schedules and options) is goeuro
This “Puente aéreo” flight connection sometimes offer great deals. You can search for those in sites like Skyscanner or eDreams. I have purchased flight tickets for €63 between Barcelona and Madrid, while the Renfe AVE tickets were quoted for €88. Flight takes less than 90 minutes, while Renfe AVE takes around 3 hours. The slower trains cost less than €30 for second class ticket. However, the travel time in non AVE train can be as high as 9 hours. Fare on ANSA bus is also around €30. Bus take 7 hours to complete the journey.