Optimal planning of thermal energy systems in a microgrid with seasonal storage and piecewise affine cost functions. (15th January 2021)