Complexity of simulating idle games (pt1)
As you have said in your question, non-cyclical resource production is easy to simulate, but let's describe the simple case before seeing how it impacts the answer. For our cookie-bakery scenario, this is the setup:
$$
t_i=0,\ t_f=100 \\
C_i=567,\ C_{cpt}=0,\ C_{bpt}=0 \\
B_i=10,\ B_{cpt}=2,\ B_{bpt}=0
$$
The above describes the initial state of our game, we currently have 567 cookies and 10 bakeries. It also describes the production statistics, how much each resource produces per tick. For us, cookies produce nothing and bakeries produce 2 cookies per tick. How do we find how many cookies there are when the time is up?
$$
C(t_f)=\int_{t_i}^{t_f}\frac{dC}{dt}dt+C_i=2567
$$
This function will calculate how many cookies have been produced by time $t_f$. In our simple case, $\frac{dC}{dt}$ is easy to calculate:
$$
\frac{dC}{dt}=B_{cpt}B(t)=20
$$
Since there are no new bakeries being generated, the number of bakeries is constant $B(t)=B_i$.

Question 1
The trouble begins when the resource production contains cycles. That is to say, $\frac{dC}{dt}$ is dependent on $C(t)$ itself. We have entered the realm of differental equations. For an example, here is a tweaked setup where cookies can also asexually reproduce every tick:
$$
t_i=0,\ t_f=100 \\
C_i=567,\ C_{cpt}=1,\ C_{bpt}=0 \\
B_i=10,\ B_{cpt}=2,\ B_{bpt}=0
$$
Now the rate of change for cookies looks like:
$$
\frac{dC}{dt}=B_{cpt}B(t)+C_{cpt}C(t)\text{ where }C(0)=C_i
$$
For our case, this is a linear first-order differential equation, our integrating factor is:
$$
\mu(t)=e^{-C_{cpt}t}
$$
Plug it into the differential equation form:
$$
C(t)=\frac{B_{cpt}B(t)}{-C_{cpt}}+ce^{C_{cpt}t}
$$
Find our constant $c$ by checking the initial condition:
$$
C(0)=\frac{B_{cpt}B(0)}{-C_{cpt}}+ce^0=C_i \\
c=C_i+\frac{B_{cpt}B_i}{C_{cpt}}
$$
Plug it back into our original equation:
$$
C(t_f)=\frac{B_{cpt}B(t_f)}{-C_{cpt}}+\bigg(C_i+\frac{B_{cpt}B_i}{C_{cpt}}\bigg)e^{C_{cpt}t_f} \approx 1.58\times 10^{46}
$$
The asexual reproduction of cookies produces substantially more cookies than just bakeries, but keep in mind the cookie population is essentially doubling every time plus new cookies are being produced by bakeries.
This method can be extended for larger cycles instead of just self cyclical, but it requires higher order differential equations.
Note: Since we are just evaluating an exponential function, it is extraordinarily efficient, $O(1)$. However, this solution adapts the mathematics of population growth estimates to fit this discrete system and will only produce an approximation. Depending on how many timesteps are required to simulate, it may be preferable to spend more time computing an exact result.

Question 2
Automatic buying is quite a bit more difficult to achieve because the functions showing resource counts are no longer smooth and continuous.

This graph shows the cookie production assuming starting with one bakery &amp; zero cookies and buying another bakery every thousand cookies. The period of the function decreases with time because more and more bakeries are added to produce cookies. An estimation could be created by fitting a function to the period, but I do not know of a method to exactly count the number of bakeries and cookies without checking each timestep.