Separation of sets and optimality conditions