Companies are racking up hefty bills as they invest in new facilities and products to reduce emissions or meet other targets, hoping for a payoff down the road.