We had planned to take a train back to Madrid at the end of our trip. Is an overnight train our only option? We'd rather not. Is it better to fly or take a bus?
I think I would fly. Check kayak.com for airlines and prices. If TAP and Vueling don't come up, check their websites. Maybe there are other low cost lines as well.
Consider changing your flight home from Madrid to Lisbon. Yeah, you'll probably have to pay some extra for that, but 1) you'll have to pay to get from Lisbon to Madrid anyway (probably flying - its a long bus ride), and 2) that would effectively buy you an extra day in Europe - isn't that worth something? 3) It would also reduce the stress of trying to make critical connections at the end of your trip when you will probably be a bit worn down.