The 18-race deal provides critical stability for Hamlin and Joe Gibbs Racing after the end of a 20-year partnership with FedEx.