Having experience with solar water collectors and flow-through water heaters as a backup system, this can be accomplished.
What you will need to verify when purchasing a tankless water heater is that its heating element is triggered by the temperature of the water and not flow.
This will allow the tankless water heater to operate only when the water temp is below a set value.
For more information:
Read Kevin Burrell's Q&A "Do hot water recirculation systems work? What kind would you recommend?"