when formula 1 started, there weren't teams like red bull in it. it was honda, toyota, bmw, etc etc. like mclaren now. they use formula 1 not only as a media and money generating machine, but also for research and development to develop new parts, or processes or whatever so that they can use them in cars they sell.
and this is only formula 1, there's so many other racing series out there. AUDI is pretty big on Lemans and they're making strides in developing tdi engines with crazy mileage and power. porsche used racing to develop their new hybrid supercar, same as the la ferrari and mclaren P1.
there would be no point to racing otherwise, they're not doing it for fun.