Will a 2006 taurus auto transmission fit a 2004 ford taurus?

I have a 2004 ford taurus with an auto transmission. At first it was jumping out of overdrive, now it won't go in to overdrive and it slips.

Yes, it should, BUT if you pull a trans out of a junked car, there's no guarantee that it will be in any better condition. It might be cheaper and less complicated to just have the transmission you now have serviced by a competent transmission shop.