Try behavioral modification therapy.
You don't need to book an expensive psych ..
So you stay vigilant, and try to catch yourself grinding your teeth, and when you crave Coffee
When either event happens.. Just slap your both your thighs as hard as you possibly can..
You have to be very watchful, and make sure to do this consistently..
After you've hit yourself, close your eyes, visualize and think about WHY this just happened, the cause (teeth grinding or coffee craving), the effect (pain).
Build that association strongly in your mind.. it's a mental correction as much as it is physical.
They have the rubber band on the wrist for smokers, but that doesn't work for most people.. NOT ENOUGH pain.. the consequence is too light.
I wouldn't recommend shock therapy unless it's an extremely detrimental habit that you're trying to change.
Be careful, don't do this while you're driving, it's the only exception.. but make sure to do it right after you get out of the car.. and again, Visualize and think about cause and effect..