Microarray devices are powerful for detecting and analyzing biological targets. However, the potential of these devices may not be fully realized due to the lack of optimization of their design and implementation. In this work, we consider a microsphere-trap array device by employing microfluidic techniques and a hydrodynamic trapping mechanism. We design a novel geometric structure of the trap array in the device, and develop a comprehensive and robust framework to optimize the values of the geometric parameters to maximize the microsphere arrays' packing density. We also simultaneously optimize multiple criteria, such as efficiently immobilizing a single microsphere in each trap, effectively eliminating fluidic errors such as channel clogging and multiple microspheres in a single trap, minimizing errors in subsequent imaging experiments, and easily recovering targets. We use finite element simulations to validate the trapping mechanism of the device, and to study the effects of the optimization geometric parameters. We further perform microsphere-trapping experiments using the optimized device and a device with randomly selected geometric parameters, which we denote as the un-optimized device. These experiments demonstrate easy control of the transportation and manipulation of the microspheres in the optimized device. They also show that the optimized device greatly outperforms the un-optimized device by increasing the packing density by a factor of two, improving the microsphere trapping efficiency from 58% to 99%, and reducing fluidic errors from 48% to a negligible level (less than 1%). The optimization framework lays the foundation for the future goal of developing a modular, reliable, efficient, and inexpensive lab-on-a-chip system.