Tesla has reached an agreement to acquire SolarCity in an all-stock deal worth $2.6 billion. The companies hope that by joining forces they'll be able to operate more efficiently and create fully integrated residential, commercial and grid-scale products.

The deal is a major part of Elon Musk's broad and ambitious 'master plan' to become the only place customers need to go for all their clean energy requirements. The combined entity would be able sell solar panels, home battery storage systems and electric cars under a single brand right away. Going forward the plan is to create a single "solar-roof-with-battery-product" that can cleanly power people's homes, as well as expand Tesla's line-up of electric vehicles to include public transit systems and heavy-duty trucks.

The automaker initially offered to acquire SolarCity back in June, a controversial move not only because Musk owns 22% of SolarCity and sits on the company's board, but also given both companies are still losing millions every quarter.

Tesla says a special committee of "independent and disinterested" SolarCity board members evaluated the proposal. Musk and other executives who sit on the the boards of both companies recused themselves from voting on the outcome of the deal.

The companies said they expected the transaction to close in the fourth quarter after a 45-day "go-shop" period where SolarCity would be open to alternative proposals for purchase.