I am also an advocate for doing things early

. When babies are born, one of the Major reasons they cry is when they need a nappy change (why, because its uncomfortable having poop or wet nappy). The older they get, the more they get used to it. The less quicker they cry about it, the less quicker we (as parents) change them out of their diapers. So babies cultivate the habit of functioning in dirty diapers. It then becomes a case of unlearning, unlearning of a bad habit. I would say it is better (and costs less money and energy in all) to be proactive about your child not cultivating a bad habit in the first place than trying to break the habit.
I think its also always a case on Mum and Dad being disciplined (like
laughingwater said) setting the timer (if needed) for every 30mins or so take take your child to the toilet and ofcourse talking about other members of the family also going to the toilet. After sometime by law of association, your child figures out the toilet is where everyone poops and pees and follows suit.
With night times, my husband or I used to take our oldest out of bed at 12pm (b4 we went to bed) every night and sit her on the toilet (whilst she was still sleepy). Sometimes she peed and sometimes not but after about a month or so she would wake up herself 'around 12pm' and was led to the toilet (after a few times she started going herself) and eventually she no longer needed to pee during the night (on a daily basis).
So if you can, do it early. Generally i'd say if your child can tell you they want to eat or drink, they can also tell you they need to pee.