Japan and the US say they have reached an agreement to relocate a controversial US military base in Okinawa.