Energy conservation of piston and flywheel The question concerns classical mechanics and conservation of energy.
Imagine a piston in a cylinder, lying down so that the piston moves horizontally. 
The cylinder is open at both ends (no compression of a gas).
For simplicity, lets assume no friction, no sound, no heat effects, no gravity, and that the system is isolated in a vacuum. 
The piston has a connecting rod attached to a revolving flywheel. Consequently the 
piston oscillates back and forth within the cylinder. 
The motion of the piston resembles simple harmonic motion ; its kinetic energy occilates across time, between a maximum
at the middle of the cylinder, to zero at either end of the cylinder. 
For simple harmonic motion (e.g., a weight attached to a spring, and oscillating horizontally on a frictionless table top), 
it is well known that oscillation of kinetic energy of the weight is 
counterbalanced exactly by a coincident oscillation of potential energy 
(e.g., potential energy due to compression of a spring) in such a way that the total energy remains constant at all times:
K = E sin^2(wt)
P = E cos^2(wt)
K + P = E
Furthermore, such motion is indefinite (excluding friction, etc...).
The question is: for the system described above involving the piston, cylinder and flywheel, where does the kinetic energy "go" 
as the piston slows down towards its stationary point at the extremes of its cylinder?
From whence does it return as the piston accellerates towards its maximum kinetic energy at the middle of the cylinder?
How does conservation of energy work for this system? What are the energy/time equations for this system?
Does the flywheel revolve indefinitely with constant angular momentum, or must it slow down somehow?
 A: One would have to consider the free dynamics of the piston and flywheel. No exterior forces (other than those that keep the piston in some line) or losses, why would an unpowered flywheel always move at a constant rotational velocity if the joint between it and the piston pushes it around?
If you write out your equations of motion, they will show that the angular speed of the flywheel needs to change, which means you won't get the nice harmonic motion you're looking for. So the kinetic energy will actually balance between the two bodies, the flywheel and the piston.
7/14 Edit: You called out the jerkiness of the motion and you were right to be suspicious of it. Turns out what I had before didn't have constant kinetic energy, so that couldn't be right. I redid it, I also did it with a massless connecting rod, which allowed for a convenient substitution. There exists some value $M$ such that $I_f=Mr^2$ and this will allow for quite a bit to simplify, similarly, we can use $\rho=l/r$, a ratio of the distance which the connecting rod connects to the flywheel $r$ to the length of the connecting rod $l$.
Since I made a mistake the last time, I'll type the whole derivation up here since I'll have to stare at it more and potentially find any issues on my own.
Position is defined by only the orientation of the flywheel $\theta$. Since it's convenient the angle formed by the connecting rod and line which the piston travels, $\phi$
$$ 
s = r~(cos\theta + \rho~cos\phi) \\
sin\theta = \rho~sin\phi \\
\rho~cos\phi=\sqrt{\rho^2-sin^2\theta} \\
s = r~cos\theta + r\sqrt{\rho^2-sin^2\theta}
$$
Velocity is just a derivative and it's all on the same axis so there's no effects from the rotation,
$$
v = -r\dot{\theta}~sin\theta + \frac{-r\dot{\theta}~sin\theta~cos\theta}{\sqrt{\rho^2-sin^2\theta}} \\
v = -r\dot{\theta}~sin\theta~ f(\theta) \\
f(\theta) = 1 + \frac{cos\theta}{\sqrt{\rho^2-sin^2\theta}}
$$
Kinetic energy will be,
$$
T = m/2~v^2 + M~r^2\dot{\theta}^2 = M/2~r^2\dot{\theta}^2~g(\theta), \\
g(\theta) = 1 + \mu~sin^2\theta~f(\theta)^2
$$
Euler-Lagrange equations will be as follows, notice in the second of these, we see the momentum is not constant.
$$
\frac{d}{dt}\frac{\partial T}{\partial \dot{\theta}} = \frac{\partial T}{\partial \theta} \\
\frac{d}{dt}\bigg[ Mr^2\dot\theta \bigg] = M/2~r^2 \dot\theta^2 g'(\theta) \\
\ddot\theta~g(\theta)+ \dot\theta^2 g'(\theta) = 1/2\dot\theta^2 g'(\theta) \\
\ddot\theta = -\frac{\dot\theta^2g'(\theta)}{2~g(\theta)}
$$
I used matlab's ode45 with the initial conditions of the piston at furthest distance and the rotation was 1 rad/s to produce the position and velocity of the flywheel, also I used $r=2$, $l=10$, and $\mu=0.1$ Then I used the equations derived before for the motion of the piston. Then the energies divided the -somewhat- mass of the flywheel, $M$, would just be,
KEf = r^2/2 * dq.^2; % flywheel energy per it's mass
KEp =  mu/2 * dx.^2;   % piston energy per flywheel mass

Then I plotted the motions, each of their normalized energies, and here they are.


The motion is a lot smoother, and the thing that I'm using to identify this not guaranteed wrong is that the total energy is constant.
A: An ME could probably give a better answer, but I’ll give it a try.
The question is: for the system described above involving the piston, cylinder and flywheel, where does the kinetic energy "go" as the piston slows down towards its stationary point at the extremes of its cylinder? From whence does it return as the piston accelerates towards its maximum kinetic energy at the middle of the cylinder? 
The short answer is the flywheel transfers kinetic energy to the piston in moving from one extreme to the center of the cylinder and the piston transfers the same amount of kinetic energy back to the flywheel as it goes from the center to the other extreme (assumes lossless flywheel and piston).
Refer to the figures below.
A flywheel is designed to efficiently store rotational kinetic energy. It resists changes in rpm by virtue of its rotational  moment of inertia. The stored energy is proportional to the square of its rpm and proportional to its moment of inertia.
A flywheel changes its speed (and thus kinetic energy) when a torque is applied to it aligned with its axis of symmetry. 
In Figures 1 and 5 the applied torque is zero. This corresponds to the maximum rpm (kinetic energy) of the flywheel and zero motion (kinetic energy) of the piston at the extremes.
In Figure 3 the applied torque to the flywheel is a maximum. This corresponds to the minimum rpm (kinetic energy) of the flywheel and maximum motion (kinetic energy) of the piston at the mid point. 
The exchange of  kinetic energy between the flywheel and piston can also be described in terms of the work-energy principle, which can be stated as follows:
The change in the kinetic energy of an object is equal to the net work done on the object.
In going from Figure 1 to Figure 3  the flywheel does positive work on the piston.  This results in a positive change in kinetic energy of the piston equal to the work done on the piston, and an equal negative change in kinetic energy of the flywheel.
In going from Figure 3 to Figure 5 the piston undergoes negative acceleration. The acceleration (and therefore force) on the piston is in the opposite direction to the displacement. Thus negative work is does on the piston resulting in a negative change in kinetic energy of the piston and positive change in kinetic energy of the flywheel. 
It should be noted that the kinetic energy stored in rotational motion of the flywheel at any instant should be much greater than that in the translational motion of the piston at any instant. Consequently, for a given transfer of KE to or from the flywheel, the percentage change in rpm should be very small.
Does the flywheel revolve indefinitely with constant angular momentum, or must it slow down somehow?
In the total absence of friction in both the flywheel and the piston cylinder, the flywheel will revolve indefinitely. But there will always be some friction. 
Hope this helps. 

