The entropy generation minimization method is applied to the optimization of a buoyancy-driven laminar magnetohydrodynamic flow in a long vertical rectangular duct with thin conducting or insulating walls. The flow takes place under a strong uniform magnetic field applied transversally to one pair of walls and is driven by a known constant temperature gradient aligned with the field. Numerical solutions for the velocity and electric current density in both fluid and walls are calculated using a spectral collocation method. It is shown that an optimum value of the wall conductance ratio (i.e. the ratio of the electrical conductance of the wall to that of the fluid) that minimizes the global entropy generation rate can be found. The analysis of the irreversibilities caused by heat conduction, viscosity and Joule dissipation allows to explain the existence of the optimum value.