This is from the owner's manual for my 2007 F-150. You don't say what year yours is so this may or may not apply. First part says where you should find the code but I'm not sure where the "computer module" is located.
The proceedure is as rod has said. BUT, as a precaution, you should find the module and get the factory preset code. If you disconnect the battery, your personal code will be erased, and the only code will be the factory preset. You will have to reset your personal code. Go back to the dealer to get them to showor tell you where the module is, or have them read the code from the computer. A reputable dealer should do this without a charge, since they have already got your money for the purchase. I think that the module is in the left kickpanel, it is about the same size as the ECU, and has a label with the factory code printed on it.
Welcome to FFCars! The
representations expressed are the representations and opinions of
the FFCars.com forum members and do not necessarily reflect the
opinions and viewpoints of the site owners, moderators, Factory Five
Racing, Inc. or Ford Motor Company. This website
has been planned and developed by FFCars.com and its forum members
and should not be construed as being endorsed by Factory Five
Racing, Inc. or Ford Motor Company for any
purpose. "FFR", "Factory Five", "Factory Five Racing", and the
Factory Five Racing logo are registered trademarks of Factory Five
Racing, Inc. FFCars.com forum members agree not to
post any copyrighted material unless the copyrighted material is
owned by you. Although we do not and cannot review the messages
posted and are not responsible for the content of any of these
messages, we reserve the right to delete any message for any reason
whatsoever. You remain solely responsible for the content of your
messages, and you agree to indemnify and hold us harmless with
respect to any claim based upon transmission of your message(s).
Thank you for visiting the FFCars.com Forum dedicated to Factory