This is called bruxism, and if you google it you will find loads of information.
Interestingly there is some suggestion that there could sometimes be a lack of something in the diet linked to it.
The following is copied from Wikipedia
"There is anecdotal evidence that suggests taking certain combinations of dietary supplements may alleviate bruxism; pantothenic acid, magnesium, and calcium are mentioned on dietary supplement websites. Calcium is known to be a treatment for gastric problems, and gastric problems such as acid reflux are known to increase bruxism"
Perhaps it is worth taking something like Centrum, or another wide ranging vitamin and mineral supplement to cover all bases.