Small-scale magnetic robots that can assemble, disassemble, and propel under globally applied magnetic fields can be versatile modular subunits for manufacturing and in vivo operations. This paper presents a magnetic cuboid robot that contains assembled cubes with encapsulated freely rotating permanent magnets. This minimalistic, scalable design enables the magnetic cubes to assemble under magnetic fields into a cube chain that can propel using pivot-walking locomotion. A vision-based closed-loop controller that modulates the cuboid robot's position and orientation during pivot walking is presented. The controller is simulated to navigate cuboid robots to user-selected goal locations. A BFS (Breadth-First Search) path-planning algorithm for obstacle avoidance is used to generate optimal paths for closed-loop pivot walking.Two physical workspaces are tested, one with a large free space and the other with a maze.Experiments and simulations demonstrate that magnetic cuboid robots can navigate in complex mazes and selectively self-assemble into cube chains while following the optimal path generated by the motion planner with visual feedback control.