The Elon Musk-led EV maker has had trouble selling cars the way it once did. But a growing energy business and AI plans are helping pick up the slack.