Off[General::"spell1"]

λ1 = 0.4; λ2 = 0.04; αin = 5; αext = 15; 
    d1 = 0.45; S = 15*8*4;
Rtheta = 
      (d1/(S*λ1)) + (x/(1000  S*λ2)) + 
        (1/(αin*S)) + (1/(αext*S))

dataOrsil = {{40, 51.17}, {50, 63.07}, {60, 76.16}, {80, 
              101.15}, {100, 127.33}, {120, 152.32}, {140, 177.31}, {160, 
              203.49}, {180, 228.48}, {200, 254.66}} /. {a_, b_} -> {a, 
              S*b};
nahrada = Fit[dataOrsil, {1, x}, x]
Show[
        ListPlot[dataOrsil, PlotJoined -> True, 
          AxesLabel -> {"x[mm]", "cena[Kc]"}, 
          DisplayFunction -> Identity], 
        Plot[nahrada, {x, 40, 200}, PlotStyle -> Hue[0], 
          DisplayFunction -> Identity], 
        DisplayFunction -> $DisplayFunction];

inflace = 1.01;
koefcenyenergie = 1.05;
prace = 100000;
investicninaklady = prace + nahrada;
Print["investicni naklady=  ", 
      investicninaklady, "  Kc"]

zivotnost = 50;
prumteplota = 0;
teplotain = 25;
den = 24*3600;
delkatopnesezony = 100*den;
cenaGJted = 250;
cenazaGJ = cenaGJted*(koefcenyenergie^i);
koefprepoctucenypenez = (inflace^(-i));
ztrataprostupem = ((teplotain - prumteplota)/Rtheta)*
          delkatopnesezony;
cenavroceitem = 
        (ztrataprostupem/(10^9))*cenazaGJ;
cenated = cenavroceitem*koefprepoctucenypenez;

cenacelkem[x_] = 
        investicninaklady + 
          Sum[cenated, {i, 0, zivotnost - 1}];
min = 
        FindMinimum[
          cenacelkem[x], {x, 50, 500}];
Print["nejvyhodnejsi tloustka=  ", 
      x /. min[[2]], " mm, naklady jsou ", 
      min[[1]], " Kc"]

Plot[{cenacelkem[x], 0}, {x, 40, 900}, PlotRange -> All, 
      AxesLabel -> {"x[mm]", "cena[Kc]"}]