In a spatially periodic temperature profile, directed transport of an overdamped Brownian particle can be induced along a periodic potential. With a load force applied to the particle, this setup can perform as a heat engine. For a given load, the optimal potential maximizes the current and thus the power output of the heat engine. We calculate the optimal potential for different temperature profiles and show that in the limit of a periodic piecewise constant temperature profile alternating between two temperatures, the optimal potential leads to a divergent current. This divergence, being an effect of both the overdamped limit and the infinite temperature gradient at the interface, would be cut off in any real experiment.