how can i restore my iphone 3gs on 4.0 and keep my unlock and jailbreak?

I know your prolly gonna say search but theres so many different options.

So can does apple still let u restore to 4.0 or can i just upgrade and jailbreak/unlock sorry i havent been here in awhile is there an unlock and jailbreak for 4.1 or the newest one? thanks