Ends do not justify means
No, it is never permissible to sin so that good may come about.
St. Paul wrote:
let us not do evil that there may come good
Rom. 5:20 & 6:1
where sin abounded, grace did more abound. […] [So] shall we continue in sin, that grace may abound? God forbid.
Grace is always sufficient to doing good:
2 Cor. 12:9
My grace is sufficient for thee
Soul to be preferred over the body
Both the body and soul are goods, and it is against the 5th Commandment to do bodily or spiritual harm to oneself, but usually the body (a good) is against the soul (another good):
Gal. 5:16-17I say then, walk in the spirit, and you shall not fulfill the lusts of the flesh. For the flesh lusteth against the spirit: and the spirit against the flesh; for these are contrary one to another.
This is why the Church prescribes fasting and abstinence, for mortifying our evil inclinations.
Because we are dealing with two goods (body and soul), we must apply the principle of double-effect (cf. this Christianity StackExchange answer) and prefer the soul over the body:
Mat. 10:28…fear ye not them that kill the body, and are not able to kill the soul: but rather fear him that can destroy both soul and body in hell.
Tolerating evil to prevent greater evil or to do greater good
Sin can be tolerated in order to prevent a greater evil. For example, a ruler could tolerate the evil ideology of Islam because if he condemned it, it might excite Muslims to greater violence and make Christians lose their faith.
Addressing the question of "Whether the rites of unbelievers ought to be tolerated?," St. Thomas Aquinas says:
…although God is all-powerful and supremely good, nevertheless He allows certain evils to take place in the universe, which He might prevent, lest, without them, greater goods might be forfeited, or greater evils ensue. Accordingly in human government also, those who are in authority, rightly tolerate certain evils, lest certain goods be lost, or certain greater evils be incurred: thus Augustine says (De Ordine ii, 4): "If you do away with harlots, the world will be convulsed with lust." …