Remove all the items on the shelves. If possible, remove the shelves as well and set up a work bench in the basement or garage. With a steady hand, or masking tape, you should be able to avoid getting paint on the remaining metal brackets.
Clean the shelves with grease-cutting detergent, such as dishwashing detergent, and a sanding sponge or wet-dry sandpaper to abrade the surface at the same time. Rinse them and allow to dry.
Prime all the surfaces of the built-in shelves with stain-blocking primer if they are currently unpainted. Use either tinted shellac primer, fast-drying oil-based primer or two coats of a quality water-based primer. If the shelves are currently painted with water-based paint, skip this step.
Caulk gaps and joints in corners and along the edges of fixed shelves. Smooth the caulking with a damp rag and let it dry for a few hours before painting.
Cut in all the edges and corners of the built-in shelves with a 2- or 3-inch brush. If the shelves are narrow, look for short-handled brushes that are easier to maneuver in tight spaces.
Roll the shelves with a 6-inch roller, again with a short handle if space is tight. Wait at least eight hours for the surfaces to dry, and apply a second coat.
Wait at least 24 hours before placing anything on the shelves, and 72 hours or more before putting heavy items back. Most paint takes roughly a month to fully cure, so the longer it's allowed to dry before use, the better.