If Messrs. Musk and Rive can achieve their shared vision, the result will be a transformation of the world’s, or at least America’s, energy infrastructure. The companies the two men run— Tesla Motors Inc. and solar energy system provider SolarCity Corp. —are uniquely compatible.