How does the iPhone handle connection priority?
The iPhone will always try to connect to the wifi if it is in range. If it already knows how to connect it will do so automatically. If it does not know it will notify you that there are wifi networks available.  

But to come back to the situation you described:
If it is already connected to the wifi it will use that for all data even if it is also connected to a 3G network.