In a previous post, I explained from the Scriptures why the "gates of hell shall not prevail" in Matthew 16:18 refers to the fact that the church, i.e. all believers, will be raised to eternal life. In hindsight, I probably should have pointed out that this interpretation is also supported in the deuterocanonical book of Wisdom.
For thou hast power of life and death: thou leadest to the gates of hell, and bringest up again.
It has nothing to do with an institutional church weathering the storms of heresies, although a lot of people have mistakenly treated it that way.