Can I buy an iPhone and just use it for apps and Wi-Fi?

Can I buy an iPhone 4g or 5g and just use it for apps and Wi-Fi without signing up for a contract or anything? Do I need a sim card to use the Wi-Fi? I basically just want to use it like an iPod Touch but I don't want to have to go through a carrier, all I want is the Wi-Fi.

You could use just Wi-Fi only