Scrape loose and failing paint with a chisel-edged paint scraper, then sand the trim until it's as smooth as you can reasonably get it. A power sander with 80-grit sandpaper works well.
Prime the trim with oil-based or 100-percent acrylic primer. If it's in reasonably good condition, just prime the bare areas of the wood.
Caulk gaps in the trim. Also caulk gaps or cracks between the brick and the trim. Caulking comes in a variety of colors--use a color that most closely matches the grouting material between the bricks, such as gray, so it won't show up after you've painted the trim. Allow the caulking to dry for at least eight hours.
Apply 2-inch painters' tape to the brick around the trim. Use a folded towel to protect brick window sills from paint drips as you work.
Apply two coats of 100-percent acrylic paint to the trim. Use a 2- or 3-inch angled sash brush for windows, and a 3-inch brush or 4-inch trim roller for wider trim.