How do I the OS from my BlackBerry?

For 87xx, 81xx and 88xx series go to Options->Security Options->General Settings, hit the menu key and select Wipe Handheld.
It's the same process for the 71xx, 72xx, 75xx and 77xx except you go to Content Protection under Security Options.