Those are called tonsilloliths or tonsil stones.
While there's still some debate on how they form, one assumption is that small portions of food, in addition to bacteria, fungus, and saliva get stuck in the tonsils and "digest" leaving this hard material behind.
They're generally harmless although annoying at times. You can take a ear swab or finger and gently press the tonsil area to get them out. Gargling frequently with salt water also seems to help.
There is some suggestion that they may possibly be a sign of an EBV infection, but there aren't any studies to confirm or deny this hypothesis.