One other thing is that a lot of the teaching classes are "nominal." If you open up any course catalog for a university, you will see entries for "graduate research" or something similar. Those are "bookkeeping classes". Graduate students pay tuition which gets pooled into teaching credits, which are used to pay for teaching loads. In fact, the "class" consists of people doing research. Distance learning classes also end up with the same framework.
In addition, unlike most other occupations, universities *encourage* professors to moonlight, so it's very common for professors to have side jobs either consulting or starting their own companies. It's also encouraged for professors to take any inventions that they have, make money off of them, and start companies based on that research. Because universities are non-profits and because it's a "reputation economy" if you take your research and then start a mega-company and become a bizillionaire with the profits, the university will love you, whereas this will get you instantly fired in industry.
Also companies will often sponsor research. They give the university money with the expectation that it will go to a particular group minus a "tax" which is giving to the university. In the "mechanical world" this doesn't lead to problems, but there has been a lot of discussion about conflict of interest when it comes to biotech and social sciences (i.e. finance).