I have been reading an Economics working paper and trying to derive the first-order conditions of a seemingly complicated optimization problem.
The optimization problem with choice variables $P_{t}^{R}$, $P_{t+i}^{S}$, $H_{t+i}$ is as follows.
$$\max E_{t} \sum_{i=0}^{\infty}(1-\delta)^{i}Q_{t,t+i}\pi_{t+i} = \pi_{t} + E_{t} \sum_{i=1}^{\infty}(1-\delta)^{i}Q_{t,t+i}\pi_{t+i} = \pi_{t} + V_{t}$$
$$\pi_{t+i} = \int_{H_{t+i}}^{1}\sigma^{F}(q_{t+i}^{R})\frac{P_{t+i}^{R}-W_{t+i}}{P_{t+i}}dt + \int_{0}^{H_{t+i}}\sigma^{F}(q_{t+i}^{S})\frac{P_{t+i}^{S}-W_{t+i}}{P_{t+i}}dt - \frac{\Psi }{2} \left ( \frac{P_{t+i}^{R}}{P_{t+i-1}^{R}} - 1\right )^{2}$$
s.t. $$\sigma^{H}(q_{t+i}^{R})\left ( U-\lambda_{t+i} P_{t+i}^{R}\right ) \geq 0,$$ $$\sigma^{H}(q_{t+i}^{S})\left ( U-\lambda_{t+i} P_{t+i}^{S}\right ) \geq J_{t+i},$$ where $Q_{t,t+i}$ is the stochastic discount factor defined $Q_{t,t+i}\pi_{t+i} = \frac{\beta^{i}\lambda_{t}}{\lambda_{t+i}}$, $\sigma$'s are the probabilities.
The first-order conditions are:
$$P_{t+i}^{S} = \frac{U}{\lambda_{t+i}} + \frac{q_{t+i}^{S}e^{-q_{t+i}^{S}}}{1-e^{-q_{t+i}^{S}}} \left ( \frac{U}{\lambda_{t+i}} - W_{t+i}\right ),$$
$$\sigma^{F}(q_{t+i}^{S})\left ( P_{t+i}^{S}-W_{t+i} \right ) = \sigma^{F}(q_{t+i}^{R})\left ( P_{t+i}^{R}-W_{t+i} \right ),$$
$$\mu_{t+i}\sigma^{H}(q_{t+i}^{R})\lambda_{t+i} = Q_{t,t+i}\left [ (1-H_{t+i})\frac{\sigma^{F}(q_{t+i}^{R})}{P_{t+i}} - \frac{\Psi }{P_{t+i}^{R}-1}\left ( \frac{P_{t+i}^{R}}{P_{t+i-1}^{R}} - 1\right ) \right ] + Q_{t,t+i+1} \Psi\left ( \frac{P_{t+i+1}^{R}}{P_{t+i}^{R}} - 1\right ) \frac{P_{t+i+1}^{R}}{(P_{t+i}^{R})^{2}} = \Phi (P_{t+i}^{R}),$$ where $\mu_{t+i}$ is the Lagrange multiplier w.r.t the constraint of $P_{t+i}^{R}$.
I am not sure how the first-order conditions were derived in the paper. I think the authors used the method of Lagrange multipliers, but I am not sure how to go about it. Can anyone help me with the process of getting the above first-order conditions?
EDIT: For more information, $P_{t+i}$ is aggregate price level, $\pi_{t+i}$ is firm's real profit in period $t+i$, $V_{t}$ represents the real net present value of an existing firm at the end of the period $t$, $\sigma^{F}$ is the firm's probability of getting at least one customer facing different queue length attracted by a posted price, $W_{t+i}$ is nominal wage, $\Psi$ is price adjustment cost in real term, $\sigma^{H}$ is the customer's probability of purchasing the good at the firm visited different queue length, $\lambda_{t+i}$ is the Lagrangian multiplier in the household's problem, and $J_{t+i}$ is the sale hunter's expected utility from visiting any other firm. $q^{r}$ and $q^{s}$ are queue lengths at the regular and sale prices.