Yes, you need to do this before you leave the park on the last valid day of your ticket. Why not do it sooner though so you can enjoy some of the AP benefits (discounts) during your visit?
No. you can do it at any ticket window inside or outside of the parks