In this extremely famous soliloquy, Hamlet is considering suicide - the literal interpretation of "to be" or "not to be." He has his reasons; he has lost his father to murder, his mother has remarried quite hastily, his girlfriend is spurning him and he is not allowed to return to the university. He has already alerted the audience that the only reason he has not killed himself yet is that it is a mortal sin to do so: "...that the Everlasting had not fix'd his cannon 'gainst self- slaughter" (I,ii).
In essences, the decision to remain alive is not based upon Hamlet's religion. He rarely mentions religion in the play and continues to consider suicide even though he knows its outcome. Rather, Hamlet notes in this soliloquy that men stay alive despite oppression, labor, poverty and heartbreak and a host of other reasons because they are scared. He questions "what dreams may come?" meaning he wonders what will happen in the afterlife. Nobody has returned to tell. What if it is worse? Hamlet thus concludes that this fear:
makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all (III,i).
It is not deep religious conviction or even the necessity of revenge that keeps Hamlet from killing himself; it is the fear of the unknown that most mortals share.
It is a common misconception that the 2B soliloquy is Hamlet contemplating or considering suicide. The text doesn't support this and neither does the story or the plot. Remember, this soliloquy sits between Hamlet's plan to catch the conscience of the king and the play-within-the-play. Hamlet's pause is to consider the consequences of his plan. It's one thing to think up a plan it's quite another to "act" it out so to speak. Catching the conscience of a king can (and is proven) to be a life-threatening endeavor. That's what the soliloquy is about. The confusion comes from the cryptic nature of the speech which it is argued stems from Hamlet's awareness that he is probably being spied upon. More consistent with his character though Hamlet is searching for universal principles. With this in mind let's go to the text.
The speech is delivered in the third person. No where does Hamlet refer to himself. Rather he is speaking for all noble princes. Hamlet addresses two concepts. First, whether life is worth having and second the impediments of turning resolve (resolution) into action. The second concept naturally flows from the first because Hamlet realizes that though we just "can be" without doing anything, we can't simply "not be". Hamlet's exploration of "not being" involves 2 ways to "not be". The first is taking arms against a sea of troubles. That is taking up the sword and battling life's burdens. The second is making your own quietus with a bare bodkin. "Not being" requires some forward action beyond the mere resolution to do so. This is the second part of Hamlet's soliloquy: turning resolution into any action is generalized from the specific example of doing something to "not be".
In light of life's burdens is life worth having or not. As nobility Hamlet has had his preconceived notions of what it is to be noble. The chink in the armor is his realization that nobility is not a state of mind bestowed at birth rather it must be earned. The ultimate conclusion he draws by the end of the soliloquy is that if one settles on being noble of mind and nothing more then he is a coward -- a paradox, hardly keeping with nobility. We see this expanded in Hamlet's last soliloquy in 4.4. "How all occasions do inform against me..." where Hamlet watches Prince Fortinbras resolve to act for an "eggshell". Again the dichotomy of passive forbearance versus the nobility of action.