The ends always justify the means -- the only question is which ends you're going to consider relevant.
The classic example is the implausible question: is it acceptable to murder an infant to save 100 other lives? To vastly oversimplify, a utilitarian may say yes, because the 100 lives are cumulatively more valuable than the life of the infant; a Christian may say no, because murder is wrong no matter how many lives it saves. The disagreement isn't really over whether or not "the ends justify the means" -- the real disconnect is over how each person weighs the various ends and which ends they recognize as legitimate.
When the Christian contemplates the murder, he may consider that one of the consequences will be that he will be violating an absolute rule established by God; to the Christian, that violation -- as an end itself -- may be more weighty than saving the lives of 100 people. The Christian decides that, after examining the consequences of both action and inaction, he must choose inaction because the ends that would result from action are a net loss.
The utilitarian in the same scenario may not recognize God's commands as relevant. Perhaps he doesn't believe God exists, or perhaps he believes that God would prefer that he save 100 lives rather than obey the rules. Either way, the utilitarian could weigh the consequences of action and inaction and decide that the ends of action will result in a net gain.
I've used the term "utilitarian" here improperly (although it's commonly used this way, even by utilitarian philosophers), because as you can see both he and the "Christian" reason and make decisions in the same manner. The reason they come to different conclusions is that they aren't using the same input. If the utilitarian believed keeping God's law was more important than saving lives, he would have done so; likewise, if the Christian believed that God would prefer to save lives rather than have his laws obeyed, he would have acted.
If someone tells you that "the ends don't justify the means" they're fooling themselves by failing to identify all the ends they consider important. Most people, utilitarian and not, fail to recognize or acknowledge that a desire to adhere to some system of morality may be an important end by itself, given certain input such as a belief in God.