Yes its very easy.
Plug your old 3GS into your computer and on iTunes choose to do a backup.
Once the backup is finished plug your new iPhone 4 into your computer and iTunes will ask you if you want to restore from your last back up? Choose yes and this will transfer all your info, including texts etc., onto your new phone.