I came across this article about feeling stupid in grad school. Basically it says that if you don't feel stupid in grad school, then you're doing it wrong. You'll probably feel inadequate surrounded by brilliant people, but these same people are likely either going through or have gone through the same struggles with feeling stupid as you are, and are too ashamed/afraid to say so.
No matter what research you get into, you will find yourself falling short. You should expect your first year of research to be full of stupid blunders, frustration, and feelings of rank stupidity. This is normal.
My first research project (before grad school) was working for a theoretical biochemist. He needed me to program. I'd failed the only programming course I'd ever taken, AND I'd never even heard of the language he wanted me to use. Nonetheless, I learned to program, though I admit I was tearing my hair out the whole time.
Grad school (and beyond) is all about learning things *on your own*--that is what research is, after all! It doesn't matter that you don't have the course background to do what you need to do: you can learn to do it anyway. So explain to your advisor that you aren't as good at programming as you need to be, and make sure he gives you appropriate reference books. If he doesn't have them on hand, he should buy them for you. Compared to some costs of research, this is minimal.
Math classes: go to office hours as much as possible. Find friends in the class who understand things better than you. Grades are less important in grad school than in undergrad, so don't get too worried if you don't get an A in the class--just get through somehow.