I assume this is nearly impossible in a university with separate math and computer-science departments, due to the way funding works (correct me if I'm wrong). However, I've heard that some small universities have joint mathematics and computer-science departments. In such a case, is it possible to get a professorship with the opportunity to teach both? Would I need degrees in both to qualify for such a position?
I don't know how common this is now, but about 15 years ago I was a visiting assistant professor in mathematics at a small liberal arts college in the U.S., a position that became available because, in trying to fill a tenure-track computer science position, no suitable candidates were found by late March or early April, and so the search was ended and a new search was started for a visiting math position, with one of the math faculty members helping out by teaching a couple of beginning computer science courses and one or two of the computer science professors teaching an extra class. In fact, I had consecutive visiting positions at TWO different colleges/universities back then for this same reason (no suitable computer science candidates were found for a tenure track position), and in each case the reason the visiting position was for math and not for computer science was due to the overwhelming greater number of experienced (in teaching) candidates that a math search would generate this late in the hiring season.
The same department tried again the next year, with the same result (I believe the other place I had a visiting position at was successful the second time), and the same math faculty member pitched in again, this time I believe teaching only computer science. Over a period of several years this faculty member transitioned to computer science, and has since written two textbooks in computer science. For what it's worth, I do not think this faculty member originally had much of a background in computer science (maybe a couple of courses as an undergraduate), but I believe this person had started being interested in computer science at least a couple of years before I was there.
In my university, math and computer science are not only separate departments, they're in different colleges. (Math is in the College of Literature, Science, and the Arts; computer science is in the College of Engineering.) Nevertheless, it is possible for a faculty member to have a joint appointment and teach classes in both departments.
Yes, my university has a joint department of "Mathematics and Computer Science". Freshman year, my Computer Programming II professor taught a Discrete Math course because another professor in the department was on sabbatical.
So, yes, in my experience, it is possible for a professor to teach both Math and Computer Science. Note that my university's Math and Computer Science department is very small (4 prof, 1 adjunct).
Here's a link to the university's site (some of the information might be a little outdated, but here's an idea of this university's department).
You asked if this is possible. Absolutely! As evidence, I will point to my own department - a combined department of mathematics and computer science in a mid-sized private university in the US.
As a very specific exemplar, I'll point to my colleague Dr. Mike Slattery who teaches both programming languages as well as algebra. His research lies in the relatively rare of field of computational algebra.
In fact, our department encourages cross-over teaching and no, you do not need a degree in both mathematics and computer science.