The current study deeply investigates nanofluid's heat and mass transport in a staggered-shaped enclosure with wavy walls. A nonhomogeneous mathematical model with thermophoresis and Brownian diffusion is considered in our study. The finite element method is implemented to solve the set of governing equations. Impacts of magnetic field (B0) and its orientation (γ), undulation number (N), amplitude (A) and nanoparticle types are examined for heat and mass flow. Investigations show that the most demoting trend is obtained when the inclination of B0 is either vertical or horizontal. It is concluded that mean Nusselt (Nuavg) and Sherwood number (Shavg) are increasing functions of Ra. When Ra is changed from 103 to 107, the Shavg value is increased up to six times. The impacts of wall shape show that as we increase A, the Nuavg decreases while the maximum can be obtained for the flat boundary. For small N, Shavg is an increasing function. Shape optimization revealed that there exists a critical point between Shavg and N after which it declines. Investigations further show that this point can be changed. Some critical points have been calculated that can be counted as novel results.