BP has struck a $6bn (£4.4bn) deal to sell a majority stake in its motor oil division, Castrol, to a US investment firm.