Should I mount brackets to the wall or the shelves first?
You may not have a choice if the shelf locks in by sliding forward. If that's the case, you mount to the shelf first and then hang it on the wall. Otherwise, the wall blocks you from installing the shelf. And even if it's not necessary, you may want to do it that way to get the shelf tight to the wall. Mount the brackets 1/8" or less from the back of the shelf, so the shelf touches the wall just before they do. Then, after hanging, when you tighten the screws on the wall, the shelf will get pulled tight without any gaps.