First of all, whether the earth is rotating or everything else is rotating around it, is completely irrelevant for the question. This is just the matter of point of view.
As seen from the earth, the fixed stars rotate with period day+night. On this background, the Sun describes a circle slowly with period "one year". When one looks closely, one sees that there are TWO approximately equal (but not exactly equal) periods of the sun:
a) The time in which the Sun returns to the same position WITH RESPECT TO THE STARS. This is called "sideral year", and
b) The time in which the Sun travels from one spring equinox to another. This is called "tropical year".
The difference is roughly 50 angular seconds per year.
The difference was discovered by Hypparchus in the 2-nd century BC.
For practical purposes (agriculture) tropical year is relevant (it is the period of change of seasons). To compute its length in days, one has to observe equinoxes (or solstices). The difference in days from say a spring equinox to the next one is the tropical year. Ancients could not observe and time
them with high precision, but there is a way around this.
Suppose that you observe a solstice and another one, not the next one but $m$-th one (so that $m$ years passed from one to another). And you count days and you find that $n$ days passed from the first solstice to the other one.
Then the length of the year will be approximately $n/m$ days. If $m$ is very large,
you obtain a very good approximation. Larger the $m$, more precise the approximation is.
Systematic observations of sky were made by Babylonians since 8 century BC. At least this is the time from which continuous records survive. So at the time of
Hipparchus the data for about 6 centuries were available. (In principle. It is disputed how much did he use or know Babylonian observations. He apparently had in
his possessions the Greek records of solstices for a few centuries. Practically nothing survived of Hipparchus writings. We know about them from Ptolemy who wrote 3 centuries later).
This is how the very good approximation of the length of the tropical year was found.
Then making a calendar is a technical (but non-trivial) problem. Egyptians had a calendar with exactly 365 days in the year. So the beginning of the year was floating among the seasons. A reform was made in the 1-st century AD (Julian calendar) which decreed the year of 365 1/4 days. Though a more precise value was already known. More than a millenium later the need for a better calendar was recognized, and eventually the modern calendar (called Gregorian) was introduced.