I did just that for my location in Huntington Beach, CA.
4.5KW self-installed array with 96% inverter efficiency, azimuth 270 inclination 22º would cost about $12,000 less 30% tax credit and projects to produce 6,500 to 7,000 KWh per year. Enough to offset all charging costs for 12,000 mi per year plus reduce home usage by 2,500 to 3,000 KWh per year; at SoCal Edison tiered rates, would reduce my electric bill about $500 per year.
To get a $0.12/KWh rate here, you have to install a second dedicated meter for EV charging at a cost of about $2700 (You need an electrician to cut and splice Edison's incoming lines) and charge during off-peak hours - 10pm to 8am. 5-year TCO for my proposed $90,000 list price MS using Grid power comes out to $47,800. Solar panel scenario comes out to 5yr TCO of $48,300. Sale of house in 5-yr scenario (likely for us) would increase home value by at least as much as Solar array cost, (likely $5k more using commercial installation price) and makes fuel cost a negative $500 per year; 5yr TCO becomes $36,300
For roughly comparable cars in size and luxury I chose Lexus ES300h and Lexus ES350, both pretty loaded, at $43,900 and $42,500 respectively. 5yr TCOs for those come out to $35,000 and $38,300 respectively. Even my best scenario, with zero cost for solar, MS costs $1300 more than ES300h. Still, the premium to own a Tesla works out to less than I had expected.
BTW, I include tires at around 30k and 60k miles for all three cars (according to Lexus and Tesla service departments) and brakes according to Lexus. Depreciation for Lexus came from Edmunds.com TCO and for Tesla from used prices in the area discounted for typical used car dealer trade-in price. For 2014 and 2013 MS those prices were unexpectedly high, giving depreciation rates of 18% first year and 23% 2nd year, using today's new sales prices comparably equipped as basis. (I did not want to try to figure out prices from a year and two years ago, even though I know that they were somewhat lower then.) For depreciation in years 3,4,5, I used Edmunds' rate progression for Lexus as they had been close in the first two years. Given that Tesla will be busy rolling out the Mega battery facility, Model X and Model 3 through at least 2018, I doubt that they would lower Model S pricing even if their battery costs decrease, so I wouldn't expect a collapse in resale prices.