We present a method for numerically determining the optimal wavelengths to perform spectral unmixing in photoacoustic experiments. The proposed method employs a rugged-landscape-model-inspired stochastic hill-climbing approach that can reliably and efficiently converge to near-optimal wavelength selections. Compared to current methods, the algorithm consistently achieves superior spectral unmixing accuracy, as is demonstrated on synthetic and experimental data, while maintaining equivalent or faster run times, particularly in broad spectral ranges. The algorithm’s adaptability with respect to computational efficiency makes it effective for both targeted offline wavelength optimization and opens up prospects for time-critical, real-time wavelength correction.