Self-consistent hybrid functional for condensed systems