Depending on how the ship's engines run, one could use the concept of the fusion torch. Essentially, the body is fed into the ship's reactor (or whatever else powers it, provided that its energy output is similar or greater). The conflagration blasts it into its component atoms, which can then be collected and sorted by a device akin to a mass spectrometer. Once you have these stores of raw elemental material, you can use them as you would any other store of that same material: it is, in many ways, the ultimate form of recycling.
Research on the fusion torch didn't work out so well on Earth, but for something like a generation ship it could be ideal. There is no sanitation risk, because any pathogens on the body are blasted just as the body is. There is very little wasted matter, because every component of the body can be recycled in this way. There is very little wasted energy, beyond what is necessary for the ship to run, because you already needed to run the engines (or at least a power plant), and the sorter can also be used to recycle other matter.
In a spiritual sense, this need not be much different from how things are done now. Many religions include a concept of "returning the body to the Earth" in a symbolic sense. The process I outline above returns the body to the ship, both symbolically and, to a degree, literally.