There's a really awesome plugin, FriendlyId which will handle all this for you. Loads of really clever features, including scopes and handling of 301 redirects on title change. This differs from stackoverflow and Brian's method in that the id isn't used in the url.