In my textbook, a historical motivation for the development of differentiation is given, starting with Fermat trying to find the maxima and minima of functions. What I wanted to ask is why Fermat was interested in this problem in the first place, or to ask a more mathematical and less historical question, what some immediate applications of finding the extrema are, why would mathematicians have cared about such a problem back then?
All I can think of is trying to find the maximum and minimum heights of an object modelled in a position vs. time graph. But I would imagine that deeper questions motivated this problem?
Finding the extrema of a function can be useful in pretty much any context where you can model a real-life phenomenon through functions. Sticking to functions of one single variable:
Many magnitudes evolve through time, not just position. If you graph temperature versus time, you can find the range of temperatures an engine needs to work in. If you graph predicted value versus time, finding the maximum will tell you the optimal time to sell your stocks. If you're dealing the number of bacteria over time, you can find the time at which an infection is most dangerous and so on.
A typical geometric problem is one where you want to build a cylinder of a certain volume by using the minimum surface area possible. Think of a company who wants to sell drinks in $1$L cans reducing the costs of the materials as much as possible. You can describe the surface area of the can as a function of its radius.
This specific problem would be solved like this: let's use $h$ for height and $r$ for the radius of the (circular) base. Since the volume if fixed at $1$L, we know that $\pi r^2h=1$, so instead of $h$ I can write $\frac{1}{\pi r^2}$. The total surface area of a cylinder is $A=2 \pi r^2 + 2\pi rh = 2 \pi r^2 + \frac{2}{r}$. You can continue from here by derivating the function $A(r)$ and studying the value(s) of $r$ such that $A'(r) = 0$
Another geometry problem that can be solved through optimmizing functions would be figuring out the best angle to shoot a projectile if we intend to maximize the distance it'll reach. There are many other similar ones. For this you should calculate the final distance travelled for an arbitrary angle $\theta$ so you can define a function $D(\theta)$ to work with. Someone please check that $D(\theta) = \frac{2v^2}{g} cos \theta sin\theta$ where $v$ is the starting speed, and $g$ is the acceleration of gravity
Applications get more interesting if we also consider functions of multiple variables. For example in Statistics, we can work with the "error function" of models like linear regressions, classifiers, neural networks and so on... Once we've chosen our model and gathered the data, the error will only depend on the parameters of the model. By finding the minimum of the error function, we'll tune those parameters to get the best possible performance out of the model. You'll find many other examples of problems like this in Economics, Genetics, Optimization, Artificial Intelligence...