We propose a new error modeling and optimization-based localization approach for sensor networks in presence of range measurement errors. The approach is solely based on the concept of consistency. The error models are constructed using non-parametric statistical techniques; they do not only indicate the most likely error, but also provide the likelihood distribution of particular errors occurring. The models are evaluated using the learn-and-test method and served as the objective functions for the task of localization. In addition, we also developed a localized localization algorithm where a specified communication cost or the location accuracy is guaranteed while optimizing the other.