My grandfather raises, sells and resells livestock and I want to help him by calculating when and for what price to (re)sell or buy livestock. As far as I understand(although I have a hunch that I need something more), I need to calculate the so-called "equilibrium price". I know only school level of mathematics(I know how to plot functions, find a derivative, find a primitive function).
First, the equilibrium price is, at a very basic level, just the market price for livestock. If you have a perfectly competitive market (a lot of suppliers) and all livestock is about the same, then the market price should be about the best your grandfather can do.
That being said, there are lots of reasons why perfect competition breaks down. This can come from number of sellers (just a few for a buyer to pick from), unobserved product heterogeneity (some livestock is better than others, but can't always see it just by looking), and more. Preferences over different types of products also interact with these other issues (if there's only one person selling and he knows how much a buyer is willing to pay, he can charge exactly that amount, etc.).
This is where the profit-maximizing price issue comes in to play. Your grandfather wants to charge the price that maximizes his profit
$\pi = p*q(p) - c(q)$
with $q$ the demand function (how much he can sell at price $p$) and $c$ the cost function (how much it costs, including what is being given up, to "produce" -- whatever that means in this market -- $q$ units of the good). (Quick note: I'm abusing notation a little in the profit function, but I'm doing it to make the point). The profit maximizing price is just the price level at which the first order condition of $\pi$ is equal to zero (assuming $\pi$ satisfies some regularity conditions). This will end up in the solution that he should produce/charge such that the marginal revenue is equal to marginal cost.
Taking advantage of this in practice requires having a really good measure of both $q$ and $c$. Although difficult for economists, $c$ is usually straight forward for firms themselves to get because they can actually calculate their own costs. The difficult part for everyone is estimating $q$. It takes a lot of data and a really good model of the market, taking into account all the issues previously discussed.
This answer discusses how this might be done by really big firms. Note that one of the main methods they use is experimentation. Large firms can do this easily and often. For smaller firms -- like your grandfather's, I'd expect -- some of the best data your grandfather might have is, like @denesp pointed out in a comment, his experience. If he's been at it for a while, the data that he has gathered over time selling in this market has likely given him a pretty good feel for what he can charge for what and to whom.
To give an example of this type of experience in practice, an economist friend of mine as an undergrad used his father's hardware business as the motivation behind a paper he was writing. He decided that he would use the store's data to estimate preferences and improve profits. He ended up pitting his estimates against his father's experience-based pricing and, try as he might, could not outperform his father's method.
This is not to say that you can't use models and estimation to improve profits. It does indicate, however, that this is not a simple problem and can require a lot of pretty sophisticated methods to outperform the natural market evolution that would be in many ways already internalized by your grandfather.