How correlated are grades in math courses with potential for research? This is something that has been troubling me for a long while now. I am an undergraduate mathematics major (a sophomore), and I wish to apply to Ph.D. programs in pure mathematics in the future. I'm very passionate about research and academia.
On basis of what I've read on this website, graduate admission committees (mathematics) select candidates on basis of how capable they are of doing research in the future, and there are several indicators for this, of which grades are just one. Everyone knows that research in math and in general is a lengthy process. It is not like working on problem sets for courses or writing exam papers in 2-3 hours. It is a lengthy process in the sense that people take months, sometimes years to solve problems and publish papers (I hope that I'm right?)
That being said, to what extent are grades and potential for research (and in turn, graduate admissions) correlated?
While getting As does signify that one has probably mastered the material, is getting a few  Bs really that bad? I'm sure this isn't something new that I've thought of, so how do graduate admissions committees deal with this problem - i.e. making sure capable and deserving candidates are not left just because of their grades (none less than B) in some courses?
P.S. We know that LoRs, and other things matter too - but I don't know how important each component is, and hence the question. This question specifically targets to ask how important grades are and how this obvious problem is addressed.
Like most things, there is some correlation, but it's not perfect. In other words, good grades are an indicator of future success, but not proof.
This is why most places look at a wide variety of things, not just GPA or individual grades. In the US, letters of recommendation carry quite a lot of weight, for example.
No, a few B grades probably won't hurt (much), especially if they are in a topic that you don't intend to pursue further. Note that true insight into mathematics isn't uniform across sub fields. For example, I had great insight into real analysis and point-set topology, but very little in algebra or even in some other aspects of analysis. But I did fine, since I worked in an area where my insight was deep.
I'll note that when I took the GRE subject test in mathematics I was extremely discouraged when I left the test center. There were so many questions that I had no insight in to at all. But that was really because mathematics is so broad that no one (anymore) can understand all of it (not since the early 20th century, I think). I did well and got into good graduate programs.
However, don't neglect the fact that good programs are very competitive.
The key is to put together a complete application (including letters) through which a reader can have confidence in making a  prediction of your future success. If you get to write a Statement of Purpose (SoP), make it forward looking, not just a recapitulation of what is in the CV. Goals, plans, ...