The U.S. government issued a rare public warning that sophisticated hackers are targeting energy and industrial firms, the latest sign that cyberattacks present an increasing threat to the power industry and other public infrastructure.