Non-line-of-sight (NLOS) propagation is one of the main error sources in indoor localization, so a large body of work has been dedicated to identifying and mitigating NLOS errors. The most accurate NLOS detection methods often rely on large training data sets that are time-consuming to obtain and depend on the environment and hardware. We propose a method for detecting NLOS distance measurements without manually collected training data and knowledge of channel statistics. Instead, the algorithm generates LOS/NLOS labels for sets of distance measurements between fixed sensors and the mobile target based on distance residuals. The residual-based detection has 70-80% accuracy but has high complexity and cannot be used with high confidence on all measurements. Therefore, we use the predicted labels and the channel impulse responses of the measurements to train a classifier that achieves over 90% accuracy and can be used on all measurements, with low complexity. After we train the classifier during an initial phase that captures specifics of the devices and of the environment, we can skip the residual-based detection and use only the trained model to classify all measurements. We also propose an NLOS mitigation method that reduces, on average, the mean and standard deviation of the localization error by 2.2 and 5.8 times, respectively.