One reason why your feet and ankles hurt is due to incorrect size of your boots. Check whether your feet slides up when you lift your foot to walk, it means your boots are big for you. Your boots should never be too big or your ankles as well as the back of your feet will rub against your boots. Your boots should not be too small, either.
Tighten the laces of your boots on downhill trails. Tying your boots tighter prevents your feet from advancing forward and eventually hitting your toes at the front part of your boots, which is painful.
Prevent your ankles from swelling by constantly taking a rest. You can take your boots off during your break, pack light and shorten your hikes. Although your feet naturally swell during a hike, too much swelling that causes pain is a tell-tale sign that your body is stressed from the hike. Try using a hiking pole to transfer too much pressure from your knees and ankle.