We have compared the ground-state energy of several observed or proposed 2 sqrt{2} x 2 sqrt{2} oxygen (O) ordered superstructures (from now on HS), with those of chain superstructures (CS) (in which the O atoms of the basal plane are ordered in chains), for different compositions x in YBa2Cu3O6+x. The model Hamiltonian contains i) the Madelung energy, ii) a term linear in the difference between Cu and O hole occupancies which controls charge transfer, and iii) covalency effects based on known results for $t-J$ models in one and two dimensions. The optimum distribution of charge is determined minimizing the total energy, and depends on two parameters which are determined from known results for x=1 and x=0.5. We obtain that on the O lean side, only CS are stable, while for x=7/8, a HS with regularly spaced O vacancies added to the x=1 structure is more stable than the corresponding CS for the same x. We find that the detailed positions of the atoms in the structure, and long-range Coulomb interactions, are crucial for the electronic structure, the mechanism of charge transfer, the stability of the different phases, and the possibility of phase separation.