To build good habits I think you have to:
1. Become conscious that you have a bad habit
2. Seek for the reason of it (often unconscious)
3. Work to shuffle off the bad habit
4. Redirect the energy that was consumed by the bad habit to develop a good habit.
Seems simple, but requires some time though.