Set clear boundaries. Even if you broke up on amicable terms, let the ex know that you don't want to be involved in every detail of their life. Perhaps you can be friends down the road, but if the breakup is fresh, let them know that you need space. Don't say things like, "I'll always love you" or "if you need me I'm there." The ex may take this as an invitation to call you for any little thing. Politely ask them not to call until you are ready.
Change your phone number, don't share it with anyone who may be persuaded to give it to your ex and don't post it anywhere online. When your ex calls and gets a disconnected message, hopefully they will get the message.
Let friends and family know. The second you start to feel the slight bit uncomfortable with an ex who keeps showing up at your job or home, you need to inform the people around you. Friends and family can go a long way in helping to keep a barrier between you and the ex.
Contact the authorities if necessary. Things can quickly get ugly if the person begins stalking. If they go out of their way to get your new phone number, leave threatening messages, talk about how they can't live without you and continue to show up everywhere you go, you must go to the authorities for your own safety. Seek a restraining order if it continues. Keep a log of every unwanted instance and save threatening voice mails as evidence to secure your restraining order.