There are some interesting prices here, but to get to the economics of the situation, I'd want to hear an economic rationale for car companies to participate, not just prices. It seems really expensive for them. I assume they're in it for the marketing? But would that money be better invested in Research & Development for their products on the road or for car commercials?
At a high level, the teams are largely their own companies that get money through sponsorships, and spend their money on developing cars. For companies like Mercedes-Benz and Red Bull Racing, it's a big advertising opportunity (and obviously a selling point for Mercedes-Benz sports cars). For teams like Williams and Force India, they're independent ventures.
Every car needs an engine, which may be developed internally or purchased from a supplier. Ferrari supplies engines for its own team (the "factory team"), but also sells engines to other teams like Toro Rosso and Sauber ("customer teams"). Engine development is extremely expensive, so amortizing the cost across several buyers makes sense. Smaller teams cannot afford to develop their own teams.
The best teams can afford to pay their own drivers lots of money, upwards of €20m/year. Some teams can only afford to pay €150k/year, and the drivers hope to prove themselves and move to a faster team after their contract is up (many top drivers came up this way). Some teams can't even afford that, and are willing to take "pay drivers," who pay the team to drive. They're not bad drivers, but they're not necessarily the best ones, either. Cutting loose a good paid driver for a worse pay driver is bad for the sport.
Participating in F1 has a unique marketing value to the right customer, and can't be replaced with just R&D or more commercials. I think it's fair to say that Ferrari wouldn't know what to do with themselves if they quit F1, as it's so much of their brand identity.