This does not include shareholders that are also employed by the company, they may choose to optimize for something else, not only financial profit.
Maximizing profit is good. Sleeping well is good. Optimizing for both is better.
Two ways:
1) you have no conscience. Which also helps you to get into the higher ranks of the company (back stabbing, bullshiting, taking credit for others et al). That puts the right people in position to both maximise profit AND sleep well (because they just don't care).
2) You just do your tiny part, it's the whole company that does the bad. You merely "follow orders" or "do what you have to do". So you sleep well. Like those guards at concentration camps slept well and were perfectly normal people (see "The Banality of Evil".
That's how, say, Coca Cola, a perfectly legit company, with people wearing $10,000 dollar suits and smiles, nice, agreeable people, employs thugs to kill workers in Latin American plants when they demand better pay. And they can keep a straight face doing so, because the actual bad doing is happening down the chain and abroad. They just demanded "efficiency" and "stop the problem" that's all. They never said how exactly.