Method of operating an energy system, said energy system comprising: - a local common transmission bus; - at least one local energy source connected to said bus; - at least one local load (11, 13) connected to said bus; - an energy store connected to said bus; - a controllable interface arranged to exchange energy between said bus and an external distribution network external to said energy system; - a controller adapted to control said interface so as to carry out said exchange of energy; characterized in that said controller is adapted to define, based on a state of charge of said energy store: - a first state of charge (E 1) corresponding to a predefined safety margin above an absolute minimum state of charge (Eo); - a second state of charge (E 2) superior to said first state of charge and corresponding to a predefined threshold above which substantially no energy can be extracted from said external distribution network; - a third state of charge (E 4) superior to said second state of charge and corresponding to a further predefined threshold below which substantially no energy can be transferred to said external distribution network; - a fourth state of charge (E 5) corresponding to a further predefined safety margin below an absolute maximum state of charge (E 6); and wherein said controller is adapted to define: - a first mode of said system when said state of charge is between said second (E 2) and third (E 4) states of charge, in which energy is transferred to or from said energy store and no energy is exchanged with said external distribution network; - a second mode of said system when said state of charge is between said first (E 1) and second (E 2) states of charge or between said third (E 4) and fourth (E 5) states of charge, in which energy is transferred to or from said energy store for the purpose of peak-shaving and/or ramp-rate limitation, and in which energy is exchanged with the external distribution network so as to draw energy from said external distribution network when said state of charge is between said first (E 1) and second (E 2) states of charge, and so as to transfer energy to said external distribution network when said state of charge is between said third (E 4) and fourth E 5 states of charge to attempt to bring the system towards said first mode, and - a third mode of said system when said state of charge is below said first state of charge (E 1) or above said fourth state of charge (E 5), in which energy is transferred to or from said energy store for the purpose of ramp-rate limitation and in which energy is exchanged with the external distribution network so as to draw energy from said external distribution network when said state of charge is below said first state of charge (E 1) and so as to transfer energy to said external distribution network when said state of charge is above said fourth state of charge (E 5) to bring said system back to said second mode. - a local common transmission bus; - at least one local energy source connected to said bus; - at least one local load (11, 13) connected to said bus; - an energy store connected to said bus; - a controllable interface arranged to exchange energy between said bus and an external distribution network external to said energy system; - a controller adapted to control said interface so as to carry out said exchange of energy; - a first state of charge (E 1) corresponding to a predefined safety margin above an absolute minimum state of charge (Eo); - a second state of charge (E 2) superior to said first state of charge and corresponding to a predefined threshold above which substantially no energy can be extracted from said external distribution network; - a third state of charge (E 4) superior to said second state of charge and corresponding to a further predefined threshold below which substantially no energy can be transferred to said external distribution network; - a fourth state of charge (E 5) corresponding to a further predefined safety margin below an absolute maximum state of charge (E 6); - a first mode of said system when said state of charge is between said second (E 2) and third (E 4) states of charge, in which energy is transferred to or from said energy store and no energy is exchanged with said external distribution network; - a second mode of said system when said state of charge is between said first (E 1) and second (E 2) states of charge or between said third (E 4) and fourth (E 5) states of charge, in which energy is transferred to or from said energy store for the purpose of peak-shaving and/or ramp-rate limitation, and in which energy is exchanged with the external distribution network so as to draw energy from said external distribution network when said state of charge is between said first (E 1) and second (E 2) states of charge, and so as to transfer energy to said external distribution network when said state of charge is between said third (E 4) and fourth E 5 states of charge to attempt to bring the system towards said first mode, and - a third mode of said system when said state of charge is below said first state of charge (E 1) or above said fourth state of charge (E 5), in which energy is transferred to or from said energy store for the purpose of ramp-rate limitation and in which energy is exchanged with the external distribution network so as to draw energy from said external distribution network when said state of charge is below said first state of charge (E 1) and so as to transfer energy to said external distribution network when said state of charge is above said fourth state of charge (E 5) to bring said system back to said second mode.