I haven't looked at fares/rules for flights out of SFO, but usually you can get better prices out of SJC/OAK. It is possible to take a redeye out of SJC that leaves at 2300 and gets into ORD at 0500. Then catch an early flight back to SJC. By doing this you'll avoid the hotel stay. There might not be flights back to SJC for a couple hours, but the RCC opens up at 0500. If you don't want to wait for a flight back to SJC you could also request to get rerouted to SFO as it's a co-terminal.