A North Dakota refinery that was the first to be built in the United States since the 1970s has been sold at a loss, with profit…