Peddler of broken dreams, Apple has being playing a cat and mouse game with software writers who jailbreak the iPhone from Jobs' Mob walled garden of delights.
When it released the OS 4.0.1 for iPhone 4, 3GS and 3G it was no different, only this time it was fairly clear Apple's heart was not in it. Apparently Apple forgot to update the baseband from 05.13.04, which means you can unlock your iPhone even on the latest iOS 4.0.1 firmware.
There is no jailbreak tool available for iPhone 4 and iPhone 3GS and the current jailbreak tools for iPhone 3GS are not compatible with iOS 4.0.1, so the only device which can currently be jailbroken and unlocked on iOS 4.0.1 is iPhone 3G.
The instructions for jailbreaking are fairly simple and can be found here.