In general, the answer to your question ('is there an algorithm available to sort the objects in the correct order?') in arbitrary 3d settings is no - no such algorithm can exist, even when the objects are as simple as triangles. It's easy to construct three triangles with a cyclic overlap; for instance, imagine looking down the Z axis at three long, thin triangles:
- A: (2.1, 1.9, 1), (1.9, 2.1, 1), (-1, -1, 0)
- B: (-2.1, 1.9, 0), (-1.9, 2.1, 0), (1, -1, 1)
- C: (2.1, 1, 0), (1.9, 1, 0), (-2, 1, 1)
Then where A and B overlap on-screen (near the XY point (0,0)), B will be on top (have the higher Z value): its Z value will be approximately 0.66 whereas A's will be approximately 0.33. Similarly, where A and C overlap (near the XY point (1, 1)), A will be on top; and where B and C overlap (near the XY point (1, -1)), C will be on top. There's no way of ordering these three triangles such that drawing them to screen in the specified order will give the correct result.
As Nathan Reed suggests, the fact that you're in an isometric view means that you would probably be able to avoid this particular issue; the question is whether it's worth avoiding or not, and that's more contingent on your environment and the particular functionality you have available. Most platforms you could be developing on have at least some form of 3d rendering readily available, though, and my first inclination would be to just piggyback on top of that for your purposes.