NextEra Energy agreed to buy Energy Future Holdings' stake in Oncor, in a deal that values the electricity transmissions business at $18.4 billion.