"Where there's muck there's money" is as true today as when it was first said generations ago. So much so, that livestock farmers' attitude to muck or farmyard manure (FYM) and slurry, the end products created by animal excrement and urine, has changed over recent years.

Slurry is a mixture of dung and urine that is collected from cattle and pig sheds and stored to be spread on the land as an organic, liquid fertiliser. FYM is a mixture of dung, urine and straw that is composted in a stack before being spread on the land.

Both of those smelly by-products of livestock production were, until recently, considered by many to be a nuisance that were spread on the land at the farmer's convenience. Soaring fertiliser costs have put paid to that wasteful attitude and most farmers now take great care to spread them at those times of the year when grassland and crops can make most use of them.

Properly used, such so-called animal waste can save thousands of pounds a year in fertiliser bills, as it can be a valuable source of plant nutrients like nitrogen and potash. Ammonium nitrate costs around £230 per tonne and a good blended fertiliser about £50 more. A twenty-tonne lorry load can set you back by about £5,500. The typical fertiliser bill for a 300-acres dairy farm may well have run to a hefty £30,000 or more this year.

While valuing slurry is not a precise science, as it depends on the animals' diet and how long they stay indoors, a typical dairy cow will produce the equivalent fertiliser value of around £75 annually. So the annual output of slurry from a 200-cow herd could be worth about £15,000 or more - little wonder that slurry is now regarded as a valuable commodity.

Well-rotted FYM not only nourishes the soil, it can also help condition it by making it more friable and improving its ability to retain moisture.

Apart from its value as a fertiliser, dung can tell a lot about the wellbeing of the animals that passed it. All farmers are concerned about how efficiently their animals convert feed into meat or milk. So it's important that they digest feed properly in order to make a profit.

Take as a crude example two dairy cows that eat exactly the same amount of identical feed. One cow converts her food more efficiently and as a result yields 26 litres of milk every day as opposed to the other that yields 24 litres. That slight improvement in yield of two litres is worth an extra 48p per day at an ex-farm price of 24p per litre, which could be the difference between profit and loss.

Canny dairymen look at the cow's dung pats to see if they're getting it right. Very liquid, runny, shallow puddles indicate excess protein or starch, or insufficient fibre. Firm dung balls that stack easily to 10 centimetres high suggest too much fibre, or dehydration as a result of a lack of drinking water. The ideal dung pat has the consistency of porridge and stands about three centimetres high with four or six concentric rings and a clearly defined "plop" in the centre.

Some farmers are now using anaerobic digesters (AD) to produce methane from slurry for use in heating systems or to generate electricity. One dairy farmer who has installed an AD plant to generate electricity that is sold into the national grid, jokingly told me: "Currently the slurry from my cows is the product with value, while milk has become a by-product of little value." He reckons that the slurry from each of his cows will generate about £140 worth of electricity every year.

For those who can afford the hefty initial capital cost of installing the technology, AD is a perfect environmental solution for handling slurry from a large dairy herd. It makes a lot of sense to use slurry in a holistic approach that improves fertiliser quality, reduces smells and generates electricity and heat.

Odour from the material left after the slurry has been "digested" is reduced by 90 per cent compared to untreated slurry, and that could be important to those farmers spreading it within close proximity to villages and towns.

Although AD is not new, there are only a few plants operating on Scottish farms and investment in the technology is being hampered by the current downturn in the profitability of milk production.