Wisconsin dairy farmer Art Thelen was full of optimism a decade ago when he joined a growing group of U.S. farmers investing in technology that turns livestock manure into electricity.

The systems promised to curb air pollution from agriculture, generate extra revenue and—in no small feat—curtail odors that waft for miles in much of farm country.

“It...