Impurity-induced localization of Bose-Einstein condensates in one-dimensional optical lattices