This happens to just about everyone somewhere along the line. I had made a bad/silly mistake in an algorithm that detected bad bots and resulted in about 24,000 pages that told Google that it was a bad bot. Kinda funny when you think about it!
You are not penalized.
Your pages rank should all come back just fine. You were just serving the wrong page. Once Google fetches your pages again, the process will begin anew.
It will take time for the pages to make their way through the SERPs to where they should rank. It could take weeks or months on a per page basis, however, everything should be fine in the end.
The recovery speed depends upon how fresh or important Google thinks the pages are. Most of mine came back fairly quickly and some took about two months. I never really lost rank through the process. The only thing I really did was confuse Google.
For pages that are most important, I suggest using Googles Fetch as Google and Submit to Index options. There is a limit per day; the last I looked it was 500 pages. I do not recommend maxing this out. However, you can spread out quite a few fetches and submits over a week. Keep in mind, that the fetch and submit is sorta temporary until the regular googlebot visits the page 1-2 days later.
When this happens, the ranking process begins again. It can take a while to fill in all the ranking metrics, however, as long as nothing has really changed, the SERP results should be the same as before. It may take a while since CTR, Bounce Rate and other metrics can take time to recover. If you remember your college math, think if a rolling average.