Which infantery tactics (or other reasons) made Pike and Shot obsolete and what replacedit? What was the last major battle where one or both sides deployed in this formation?
Pike and shot was replaced, basically, by more shot. With the invention of the ring and later the socket bayonet, all infantry had what could be described as a short pike. While some countries, such as Sweden and Russia, retained the pike, it was slowly phased out during the latter half of the 17th century.
The late 17th century and early 18th century saw the musket become lighter, faster to reload (with prepared paper cartridges) and more reliable using flintlock rather than matchlock. Musket-armed infantry could now shoot twice to three times as fast as Gustavus Adolphus' musketmen had been able to do.
Gustavus Adolphus was the first to successfully use salvo fire to create devastating effects on enemy formations. All powers learned, and started to phase out the pike, first lowering it from 2/3 to about half, and then starting to phase it out completely.
Sweden, however did not - during the Great Nordic War 1700-1721, 1/3 of the Swedish infantry was armed with pikes. combined with the discipline, morale and cohesion of the Swedish army of the time, pike formations were able to charge home and "tumble over" enemy musket-armed infantry due to their longer pikes. The Danish army ventured to re-introduce pike formations in their army after several of their infantry formations were devastated by charing Swedish pikemen at the Battle of Helsingborg 1710.
The Russians, who were more accustomed to facing Tartar, Polish, Cossack and Central Asian Khaganate cavalry armies, also retained the pike far longer than other Europeans.
Another factor in the demise of the pike was the rise in mobile light field artillery. An innovation of the Swedish armies of Gustavus Adolphus and its tactics and usage refined by Field Marshal Torstensson). When the infantry could not only shoot more, but also be supported by grape or solid shot from light cannon, which could be moved with the infantry formations, the pike formations became too unwieldy and too easy a victim to artillery and musket fire.
So, it is a combination of light artillery, the musket becoming more effective and the bayonet.