The refrigerator in the throttling example is a cyclic process which uses work to transfer heat. Similarly, heat transfers can be used to let a system do work. A heat engine is an engine that takes in heat and transforms some of it into work.
A useful way to consider the difference between the two forms of energy transferred during thermodynamic processes, heat and work, is an interpretation in terms of the kinetic energy of the atoms or molecules of the system involved in the process. Kinetic energy is the energy associated with the movements of the atoms. If these movements occur in random directions, the individual velocity (or momentum) vectors of all atoms cancel out, and no net momentum is observed. This disordered form of energy is heat. On the other hand, if all the velocity vectors are oriented in the same direction, the motion of individual atoms adds up to a macroscopic movement, and momentum is transferred at a macroscopic level. This directed, ordered form of energy is work. Energy itself is not a vector quantity, therefore there is no quantitative difference between both forms of energy, but they have a different quality attribute.
A power station is an example of a heat engine. Conventional power stations typically have a circuit in which water is pumped around. Heat coming from a combustion or nuclear reaction is fed into the circuit in a boiler, where the medium is vapourised, i.e. liquid water is turned into high-pressure steam. The pressurised steam drives a turbine, producing work, which can be used to drive a generator producing electricity. Microscopically, the turbine selects the velocity components of the steam atoms which happen to point towards the turbine blades. This is the point at which ordered energy -work- is taken from the system. The turbine effectively acts as a filter for velocity vectors.
After the turbine, the pressure of the steam will have reduced, but it cannot be fed back into the boiler as it would short-circuit the cycle, effectively reducing the pressure on the upstream side of the turbine. To avoid this, the gas is fed through a condenser, a section of pipe with diathermal walls where heat can pass through to the surroundings (e.g. through a cooling tower or nearby river). Here the gas is transformed back into a liquid which is then pumped back into the boiler to complete the cycle.
Looking at the $pV$ diagram, it is clear that this cyclic process is designed to maximise the work done by the system, i.e. the area enclosed by the cycle. By going through the liquid state in the boiler, this area is expanded into a large triangular shape. The net work done during the cycle corresponds to the difference in heat transfers in the boiler and condenser: $$W_{cyc}=Q_H-\left|Q_L\right|$$ Clearly, it would be desirable to reduce the heat lost through the condenser as much as possible, although we have seen that some heat loss is necessary because we have to return to the liquid state to complete the cycle, and that requires overcoming the heat of vapourisation in that phase transition.
The efficiency, $\eta$, of any process is, generally speaking, the ratio of desired outputs to required inputs. For a heat engine, this is the work done divided by the heat transferred from the fuel: $$\eta=\frac{\textrm{desired output}}{\textrm{required input}}=\frac{W_{cyc}}{Q_H}=1-\frac{\left|Q_L\right|}{Q_H}$$ Therefore, the efficiency depends on the ratio of the two heat transfers from and to the two reservoirs to which the heat engine is connected. In the power station case, these are the furnace in which the fuel is burnt and the cooling tower through which excess heat is dispersed to the atmosphere.
It is worth noting that the definition of efficiency in thermodynamics is a little narrower than that used in other contexts. For example, an electricity-generating company might say that they can increase the efficiency of their business by selling the excess heat to nearby customers who can use it to heat their buildings. Such combined heat and power (CHP) schemes are very useful both economically and environmentally but they do not change the thermodynamic efficiency of the power station because this only considers the work done in the process cycle.
The efficiency of a heat engine increases when the heat transfer to the cooler reservoir is minimised. The First Law doesn't prevent us from insulating the heat engine totally from the cool reservoir. If we did, we could turn all the heat extracted from the hot reservoir into work, and the efficiency would be $\eta=1$.
Microscopically, this would entail reorientating the velocity vectors of all the atoms in the system in the same
direction. To do this, we would have to supply energy. All we can do at no expense is filter out those velocity
vectors (or their components) which happen to point in the forward direction. Therefore,
there is no cycle that extracts heat from a reservoir and completely converts it to work.
This is the
Kelvin-Planck statement
of the Second Law of Thermodynamics.
A refrigerator is essentially a heat engine running in reverse; all the energy flows are reversed: $$\left|W_{cyc}\right|=\left|Q_H\right|-Q_L$$ The efficiency of a refrigerator is usually called its coefficient of performance, $\kappa$, again defined as the ratio of desired output to required input: $$\kappa=\frac{\textrm{desired output}}{\textrm{required input}}=\frac{Q_L}{\left|W_{cyc}\right|}\qquad.$$ If the reversed heat engine is operated in order to heat the outside rather than cool the inside, the desired output is $\left|Q_H\right|$ rather than $Q_L$, so the coefficient of performance of a heat pump is $$\kappa=\frac{\textrm{desired output}}{\textrm{required input}}=\frac{\left|Q_H\right|}{\left|W_{cyc}\right|}\qquad.$$ In both cases, work is used in order to transfer heat against a temperature gradient, i.e. from cold to hot.
The higher the coefficient of performance of a refrigerator or heat pump is, the less work is fed into the process, but
it does take work to transfer heat against a temperature gradient: cups of tea don't just spontaneously heat up by
taking heat from the surroundings. This is the
Clausius statement
of the Second Law:
There is no process whose sole net result is the transfer of heat from cold to hot.
While this is quite intuitive, it is not as immediately obvious as the Kelvin-Planck statement when considering the microscopic processes involved in the operation of the refrigerator: no velocity vectors need re-orientating. However. we can show that the Clausius statement and the Kelvin-Planck statement amount to the same thing.
Consider a heat engine that violates the Kelvin-Planck statement and an ordinary heat pump. If we use the work generated by this unfeasible heat engine to feed the heat pump, heat will flow from cold to hot. Since the work transferred is equal to the heat taken out of the hot reservoir $$Q_H=W_{cyc}\qquad,$$ the net amount of heat exchanged with the hot reservoir is the same as the heat taken from the cool reservoir $$Q_H''=Q_L''=Q_L'\qquad.$$ Therefore, the net effect of combining a Kelvin-Planck violating heat engine with a heat pump is a Clausius-violating heat pump.
In a very similar argument, it can be shown that a Clausius-violating heat pump coupled with an ordinary heat engine results in a Kelvin-Planck violation. Therefore the Kelvin-Planck and Clausius statements are equivalent.
It is clear from the Second Law that not all energy can be used to do work. The potential of a system to do work is determined quantitatively by its entropy.