Grid-connected and islanded operation of a hybrid power system