a perfectly competitive market will produce 0 "economic" profit (definitionally), but economic costs include opportunity costs/returns on capital. so, these firms' books' will still all show accounting profit, but this is exactly what is required to pay investors.
but, closer to what you're probably asking: very, very few markets are perfectly competitive, and, as they won't be pressured to price at marginal cost, can price higher/produce less, and thereby profit over and above a firm in a competitive market.
something like an intro to neo-classical answer:
a perfectly competitive market will produce 0 "economic" profit (definitionally), but economic costs include opportunity costs/returns on capital. so, these firms' books' will still all show accounting profit, but this is exactly what is required to pay investors.
but, closer to what you're probably asking: very, very few markets are perfectly competitive, and, as they won't be pressured to price at marginal cost, can price higher/produce less, and thereby profit over and above a firm in a competitive market.