This phrase "the gates of hell shall not prevail against it" is one I hear used often and misused often. The one point everyone seems to recognize correctly is that "it" refers to the church. Not any particular church, but the church: the body of Christ universal.
1. The "We will Survive" Error
The most frequent error I hear with respect to this verse is to imagine that the "gates of hell" are the battering rams of Satan attacking the church in this life. That's definitely not what the verse means, though one can even find this kind of view among the church fathers.
Gates are, as far as warfare goes, defensive only. They do not attack. When the enemy attacks the church he does so with firey darts, but not with gates.
2. Storming Hell? A potential error.
Oftentimes, someone who notices that the gates of hell cannot be offensive weapons of battle against the church assume that they represent the defenses of the kingdom of this world, and therefore interpret this verse as saying that the church will defeat the kingdom of this world, storming and plundering the kingdom of Satan.
This view is not completely out of the question. The basic concept is surely correct, that the church will and does (by the gospel) plunder and invade the kingdom of the world. There are two cities: the city of God and the city of man. We in the city of God are in constant spiritual warfare, and we should be engaged in the raiding parties necessary to bring souls out of the power of the kingdom of darkness.
But I think the best view of this verse is as pointing to the resurrection. The church, the body of Christ, all those who believe on the Lord Jesus Christ, will be raised to eternal life. In this view, the "gates of hell" stand simply for the bands of death.
After all, while we usually use the term "hell" to refer to the place of the damned, the term "hell" in Scripture often refers simply to the place of the dead. I think one reason people turn to interpretation (2) above is from simply hearing interpretation (1) too much. They realize that (1) is wrong, but don't recognize that this is not a warfare analogy at all.
Instead, hell is like a prison, with gates that close in the dead, so that they cannot return to life. These gates are opened with keys. This, I think, is perhaps the most crucial (key? ha!) thing that permits us to properly understand the sense of the text.
Recall that John tells us that Jesus has the keys of hell and death:
17 And when I saw him, I fell at his feet as dead. And he laid his right hand upon me, saying unto me, Fear not; I am the first and the last: 18 I am he that liveth, and was dead; and, behold, I am alive for evermore, Amen; and have the keys of hell and of death.
Notice that we know this is Jesus: he is the first and the last, the one that lives although he was dead, and now lives eternally. It is through faith in Jesus that we escape death. Indeed, it is only by faith in Jesus that we escape the bonds of death. All mankind will be raised, but those who do not trust in Christ will be raised to the second death.
This all makes sense in the context, for the very next verse continues:
Matthew 16:19 And I will give unto thee the keys of the kingdom of heaven: and whatsoever thou shalt bind on earth shall be bound in heaven: and whatsoever thou shalt loose on earth shall be loosed in heaven.
What are these keys? There is debate by some over this, but the easiest explanation is that they are the gospel: they are the way in which we are freed from the gates of hell. Thus, even as here Jesus told Peter that Peter would receive these keys, so also the same promise (without mentioning the keys specifically) is given to the other apostles:
Matthew 18:18 Verily I say unto you, Whatsoever ye shall bind on earth shall be bound in heaven: and whatsoever ye shall loose on earth shall be loosed in heaven.
The apostles fulfilled this purpose. They preached the gospel and committed Jesus' teachings to writings: the scriptures of the New Testament.
It's important to recall that this is the metaphor of the key in Scripture: it is one of unlocking and locking. Thus, we see the lawyers criticized for essentially locking away the truth of Old Testament Scripture:
Luke 11:52 Woe unto you, lawyers! for ye have taken away the key of knowledge: ye entered not in yourselves, and them that were entering in ye hindered.
In contrast, Jesus is said to have the key of David, and to be able to shut and close without contest:
Revelation 3:7 And to the angel of the church in Philadelphia write; These things saith he that is holy, he that is true, he that hath the key of David, he that openeth, and no man shutteth; and shutteth, and no man openeth;
(Quoting from: Isaiah 22:22 And the key of the house of David will I lay upon his shoulder; so he shall open, and none shall shut; and he shall shut, and none shall open.)
So, what is it that the verse is saying? It is saying, as best I understand it, that death will not prevail against the church, but rather Jesus will raise us from the dead - and that Jesus did show this way of escape (these keys of the kingdom of heaven) by which we can be loosed from(if he have faith like Peter did) and be bound in (if we do not have the faith of Peter) death.
In my opinion, the final confirmation that this is correct comes from what immediately follow verse 19:
20 Then charged he his disciples that they should tell no man that he was Jesus the Christ. 21 From that time forth began Jesus to shew unto his disciples, how that he must go unto Jerusalem, and suffer many things of the elders and chief priests and scribes, and be killed, and be raised again the third day.
This is the victory over death and hell, and these are the keys that Peter freely gave us, recorded in Peter's sermon in the second chapter of the Acts of the Apostles:
23 Him, being delivered by the determinate counsel and foreknowledge of God, ye have taken, and by wicked hands have crucified and slain: 24 Whom God hath raised up, having loosed the pains of death: because it was not possible that he should be holden of it. 25 For David speaketh concerning him, I foresaw the Lord always before my face, for he is on my right hand, that I should not be moved: 26 Therefore did my heart rejoice, and my tongue was glad; moreover also my flesh shall rest in hope: 27 Because thou wilt not leave my soul in hell, neither wilt thou suffer thine Holy One to see corruption. 28 Thou hast made known to me the ways of life; thou shalt make me full of joy with thy countenance.
Notice how the pains of death are "loosed" because they could not "hold" him. Thus, Jesus was not left in the grave, in the place of the dead, but he was raised to eternal life, as will all those who repent of their sins and trust in him.
Dear reader, if you have not repented of your sins and trusted in Jesus, do so today. It is the only way that you will prevail against the gates of hell.