Goldman Sachs is worried about rising commodity prices and higher wages, but the firm believes there is still an investment strategy that can outperform.

The firm recommended companies with high profit margins and return on assets.

That's because despite the one-time boost to profit from the corporate tax cut, companies face a number of challenges to maintaining their profit margins.

“Healthy corporate profitability continues to support equity prices ... However, the outlook for S&P 500 profitability is less constructive beyond 2018," wrote David Kostin, Goldman's chief U.S. equity strategist, in a report Friday to clients. "With the economy at full employment, higher wages and rising input costs will pose downside risks to gross margins.”

Kostin reiterated his year-end price target of 2,850 for the S&P 500, representing just 2 percent upside from Friday’s close.

The strategist noted companies with high profit margins and return on assets can do well in an inflationary environment.

“These firms are profitable from both an earnings and an asset productivity perspective and are well-positioned as margin expansion slows,” he said.

Here are five buy-rated companies in the Goldman Sachs "highest net margins and return on assets" stock basket recommended by Kostin.