From Apple's website:
Using an iPhone without a wireless service plan
* Last Modifiedecember 14, 2009
If you upgrade your iPhone to a newer model or cancel your wireless service account/tariff for your iPhone, it is possible to continue using your older iPhone without an active cellular service (using it with Wi-Fi only).
iPhone, iPhone Activation in iTunes
To do this, follow the steps for your iPhone model. Click the model of iPhone you have to see the steps for that model:
To continue using your original iPhone without active cellular service, leave the inactive SIM card in place. You will be able to use the iPhone as you would an iPod touch (Wi-Fi only, no cellular service) as long as you keep the SIM with which it was last used, even if you update or restore the operating system of the original iPhone.
Activation for an original iPhone requires that its SIM card stays with that iPhone. If the original iPhone displays the "Connect to iTunes" screen, you can use that SIM card to re-activate the iPhone, regardless of whether that SIM has a wireless service account/tariff still associated with it.
To re-activate an original iPhone that displays the "Connect to iTunes" screen:
1. Reinsert the SIM card used when the original iPhone was activated and had a valid wireless service account/tariff.
2. Connect the original iPhone to iTunes on a computer connected to the Internet.
If that SIM was previously valid and used with that original iPhone, iTunes will re-activate the iPhone, but without any cellular service.
* If you no longer have the SIM that was used with the original iPhone, and the original iPhone displays the "Connect To iTunes" screen, contact your carrier to get a replacement SIM.
* If you don't already have a wireless service account/tariff with that carrier, iTunes will help you create one.
iPhone 3G and iPhone 3GSYou can use any SIM card associated with the carrier that your device supports to activate the phone. Simply place a SIM card from the last carrier with which you used your iPhone into the device, and activate it. Then remove the SIM card. You can now use the iPhone 3G or iPhone 3GS as you would an iPod touch (Wi-Fi only, no cellular service).
Note:You can use the activated SIM card from your new iPhone to do this.
To re-activate an iPhone 3G or iPhone 3GS that displays the "Connect to iTunes" screen:
1. Insert a SIM card from the carrier with which you used your phone. Note:If you are using the same carrier, you can use the activated SIM card from your new device to do this. If your device is unlocked by your carrier, you can use any SIM card.
2. Connect the iPhone 3G or iPhone 3GS to iTunes on a computer connected to the Internet.
iTunes will then activate the device. You can remove the SIM card at this point and use the iPhone as if it were an iPod touch.